res to store the result.lastIdx to 0 to keep track of the last index processed in s.i in spaces:
a. Append the substring of s from lastIdx to i to res.
b. Append a space to res.
c. Update lastIdx to i.s from lastIdx to the end to res.res.