FastPrepReverse Each Word In Place
Problems/Reverse Each Word In Place

Reverse Each Word In Place

Citadel logoCitadel● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel Securities options software engineer interview, as the first coding round, posted in February 2025. The candidate had to fill in a C++ function reverse(begin, end) that flips the characters between two pointers, inside a short driver.

The driver passes the whole string to one reverse call, but one of its three examples flips each word on its own and leaves the spaces alone. Here, you call reverse on every word, which fits all three examples. A word is any run of non-space characters, and every space stays where it is, even repeated ones. The driver's function gives nothing back, so here it returns the new string. Only the returned string can be checked, not whether the work was done in place. The fourth example and the limits are ours.

Our version is about 80% the same as the reported question.

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) → String

Examples

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 <= 104
  • s consists 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
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public String reverseString(String s) {
      // Write your code here.
    }
}
Checking account…