Fiverr Inc. Interview Question

String with 2 words, swap words locations without using extra data structure.

Interview Answer

Anonymous

Jul 25, 2021

If 2 words are the same length, simple switching characters. else: If first(x characters) word is shorter than the second, swap x characters from the end of the string with the first word, Now the first word was moved to the end. now we have the second word in the beginning, but the right part of it in the beginning and the left part of it is in the begining. now recursively, you should do the same with the rest.

1