Frage im Vorstellungsgespräch bei Shopee

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

Antworten zu Vorstellungsgespräch

Anonym

12. März 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

Anonym

7. Jan. 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

Anonym

22. Mai 2020

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

Anonym

16. Jan. 2022

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

Anonym

7. Jan. 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