Shopee Interview Question

How to reverse a space-delimited-string word by word

Interview Answers

Anonymous

Mar 12, 2019

1) Split string into words 2) convert problem into, how to reverse a word 2.1) convert word into an array 2.2) reverse array 3) join back each individual problem

4

Anonymous

Jan 7, 2020

> loop starting from the last element It's not reverse a sentence. But reverse words in a sentence. I.e. ABC Def hij --> CBA fed jih

Anonymous

May 22, 2020

do with double linked list so only need one loop is enough. O(n)

Anonymous

Jan 16, 2022

def spaceDelimited(input: str) -> str: return " ".join(input.split(" ")[::-1])

Anonymous

Jan 7, 2020

Split the string word for word store push it in to an array Do a for loop starting from the last element of the array with the stored words to the first and print

1