Reverse Each Word In Place
Updated
Problem statement
Given a string s, reverse the characters of every word in s and return the result. A word is a run of non-space characters with a space, or the start or end of the string, on each side. Every space stays where it is, including leading, trailing and repeated spaces.
Do the work with a helper reverse(begin, end) that reverses, in place, the characters from position begin up to but not including position end. Call it once for each word. In C++ the positions are char* pointers into the string. In other languages they are indexes into a character array, and if your language cannot change a string, copy s into a character array first.
Note: the range from begin up to but not including end holds end - begin characters, so reverse(0, n) reverses a whole string of length n.
Function
reverseString(s: String) → StringExamples
Example 1
s = "Reverse"return = "esreveR"The whole string is one word, so reverse(0, 7) flips all 7 characters.
Example 2
s = " "return = " "There is no word, only one space, so nothing changes.
Example 3
s = "I Love You"return = "I evoL uoY"The words are I, Love and You. Each one is reversed where it stands, and the two spaces stay put.
Example 4
s = " ab cd "return = " ba dc "The two leading spaces, the two spaces in the middle and the trailing space stay where they are. Only ab and cd are reversed.
Constraints
1 <= s.length <= 104sconsists of English letters, digits and spaces.
More Citadel Phone Screen questions
- Merge Price-Delta FeedsPHONE SCREEN · Seen Dec 2026
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Run-Length Encoding and DecodingAirbnb · PHONE SCREENAirbnb interview questions
- Check if a String Is a PalindromeCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Reverse a StringAmazon · PHONE SCREEN
- Reverse a String ManuallyNewgen Software · PHONE SCREEN
- Reverse a String with Two PointersSnowflake · PHONE SCREENSnowflake interview questions
- Palindrome with One DeletionWhatNot · PHONE SCREENWhatNot interview questions
- Valid Word AbbreviationMeta · PHONE SCREENMeta interview questions
- Reverse a StringPersistent Systems · PHONE SCREEN
- Valid Palindrome IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences