โ† Morgan Stanley questions

Reverse words in a string based on Fibonacci series indices

Filed under Morgan Stanley

Free read 1 of 3

Confirm if word reversal means reversing the letters inside the word or reversing the positions of the words.

The question

Given a space-separated string of words, reverse the words whose 1-based index corresponds to a non-duplicate number in the Fibonacci series.

Constraints

  • 1 <= number of words <= 100
  • Words contain alphanumeric characters.

Examples

Input
s = "the quick brown fox jumps"
Output
"eht quick nworb xof jumps"
Why
Indices 1, 2, 3, 5 are Fibonacci numbers (1, 1, 2, 3, 5 - unique non-duplicate terms: 1, 2, 3, 5). The words at those indices are reversed.

Approach

  1. Confirm if word reversal means reversing the letters inside the word or reversing the positions of the words.

Tips

  • What they are testing: Test with string lengths smaller than Fibonacci values and single-word strings.
  • Common mistake: Confusing 0-based and 1-based indexing when matching against the Fibonacci sequence.

Related Morgan Stanley questions

Collected from public candidate posts and coding forums. Updated Nov 2026.