3
string reorderSpaces(string text) {8
for (int i = 0; i < text.size(); i++) {9
// Calculate the numbert of spaces10
while (i < text.size() && text[i] == ' ') {15
// Extract the words and collect them17
while (i < text.size() && text[i] != ' ') {23
// Adding word to the collection24
if (tp.size()) v.push_back(tp);29
// Combining the words with equal number of white spaces30
for (int i = 0; i < v.size() - 1; i++) {32
int j = ct / (v.size() - 1);33
while (j--) text += ' ';36
text += v[v.size() - 1];38
// Adding remaining extra spaces at the end39
int j = (v.size() > 1) ? ct % (v.size() - 1) : ct;40
while (j--) text += ' ';