Reverse the order of the words in a String in-place.

Reverse the order of the words in a String in-place.

Problem Statement

You have a string that represents an English news headline made of English words, but no punctuation, like "dog won desserts".

Part I

Write an algorithm that returns the reverse of the string, e.g. "stressed now god".

Part II

Write an algorithm that returns the reverse order of the words, e.g. "desserts won dog"

Evaluation

  • Completeness of the C# or pseudo-code algorithm, Part I (25%)
  • Completeness of the C# or pseudo-code algorithm, Part II (25%)
  • Correctness and memory efficiency of the algorithms, demonstrated by quick manual unit tests, including with super large input strings (25%)
  • Was the solution to Part I re-used to solve Part II? (if not, ask if it can be) (25%)

References

Common interview question in most places such as Google and Microsoft

Recommended reading

Author
Amin Ariana
Published
May 2007