MEDIUMasked at 1 company

Reverse Words in a String II

A medium-tier problem at 56% community acceptance, tagged with Two Pointers, String. Reported in interviews at ServiceNow and 0 others.

Founder's read

Reverse Words in a String II is a two-pointer string problem that looks trivial until you hit the constraint that kills the obvious approach. ServiceNow has asked it. The trick isn't reversing words, it's doing it in-place without extra space, which blocks the standard "split and rejoin" path every candidate's instinct reaches for first. The acceptance rate sits at 56%, meaning half the people who attempt it walk away with a failed submission. If this lands in your live OA and you blank on the two-pass technique, StealthCoder surfaces the working solution invisibly while you're screen-sharing.

Companies asking
1
Difficulty
MEDIUM
Acceptance
56%

Companies that ask "Reverse Words in a String II"

If this hits your live OA

Reverse Words in a String II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The problem forces you to abandon string libraries and think in place. Most candidates spend their first 15 minutes trying to reverse substrings after splitting, then realize they've burned the in-place requirement. The actual pattern: reverse the entire string first, then reverse each individual word. Two pointers find word boundaries, and you rebuild the string character by character without allocation. The trap is overthinking it as a parsing problem when it's really about index arithmetic and directional reversal. This specific approach only clicks when you've seen the pattern before, which is why it's dangerous in a timed assessment. That's where StealthCoder's live replay of the working algorithm becomes the safety net for the problem you didn't drill.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Reverse Words in a String II recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Reverse Words in a String II interview FAQ

Why can't I just reverse and rejoin like a normal string problem?+

The problem specifies in-place reversal with constant space. Standard split-reverse-join uses extra arrays or string builders, which violates the constraint. The two-pointer technique works around it by reversing the full string first, then flipping each word back individually.

Is this problem still asked at big tech companies?+

ServiceNow has asked it. It's not as flashy as recursive problems, but two-pointer string manipulation remains a screening filter. The 56% acceptance rate suggests it catches people off guard in interviews, so it's worth knowing the pattern.

What's the difference between this and regular string reversal?+

Regular reversal flips the whole string. This problem requires reversing word order while keeping character order within words intact. That constraint rules out naive approaches and forces you to think about two separate reversal passes.

How long should this take in an interview?+

If you know the two-pass pattern, 8 to 12 minutes. If you don't, you'll spend time backtracking from false starts with splitting or manual parsing. Having seen it before shrinks the problem to writing clean pointer logic.

Do I need to handle edge cases like multiple spaces?+

Check the problem statement for constraints. Common cases are single spaces between words, leading/trailing spaces, or multiple spaces. The two-pointer approach handles them cleanly once you know where to set boundaries, but the edge case details matter for passing all test cases.

Want the actual problem statement? View "Reverse Words in a String II" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.