Microsoft Interview Question: Given a string (understood to... | Glassdoor

Interview Question

Software Development Engineer In Test (SDET) Interview Redmond, WA

Given a string (understood to be a sentence), reverse the

  order of the words. "Hello world" becomes "world Hello"
Answer

Interview Answer

1 Answer

1

2 ways.
At the low level: reverse the entire string. 'Hello World' becomes "dlroW olleH". Then reverse each word, becomes "World Hello".
At a higher level: Tokenize the words and push them onto a stack, then pop them out.

dopey on May 6, 2011

Add Answers or Comments

To comment on this, Sign In or Sign Up.