Reverse Word Order In Place
Updated
Problem statement
Given a mutable character array chars representing a sentence, reverse the order of its words while keeping the characters inside each word in their original order. Modify the supplied array in place using constant auxiliary workspace, then return the same array.
Every word contains ASCII letters. Adjacent words are separated by exactly one ASCII space, with no leading or trailing space. An empty array represents an empty sentence.
Function
reverseWordOrderInPlace(chars: char[]) → char[]Examples
Example 1
chars = ["s","k","y"," ","i","s"," ","b","l","u","e"]return = ["b","l","u","e"," ","i","s"," ","s","k","y"]Reverse three words without reversing their letters.
Example 2
chars = ["M","L"]return = ["M","L"]A single word has no word-order change.
Example 3
chars = []return = []The empty character array has no words.
Constraints
0 <= chars.length <= 2000.- Each nonempty word contains only
A-Zora-z. - Words are separated by one space and there are no leading or trailing spaces.
More Microsoft Phone Screen questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
- Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
- Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
- 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
- Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
- Most Visited String SectorsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Add Signed Character ArraysByteDance · PHONE SCREEN
- Objects Seen on Both Days by Multiple ClientsGoogle · PHONE SCREEN
- Reverse the Interior of Vowel-Bounded WordsVisa · OA
- Reverse the Interior of Vowel-Bounded WordsZipRecruiter · OA
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEW
- Linked Merchants Within Two HopsStripe · PHONE SCREEN
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEW
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEW
- Run-Length Encoded Vector Dot ProductMeta · PHONE SCREEN · ONSITE INTERVIEW
- Interval List IntersectionsGrammarly · PHONE SCREEN