MEDIUMasked at 24 companies

Reverse Words in a String

A medium-tier problem at 52% community acceptance, tagged with Two Pointers, String. Reported in interviews at HPE and 23 others.

Founder's read

Reverse Words in a String shows up across 24 companies, from HPE and Visa to Snap and Yelp. It's a medium-difficulty string problem with a 52% acceptance rate, which means half the candidates who attempt it fail. The trick isn't obvious on first read. Most people split by spaces, reverse the array, and rejoin. That works. But interviewers often want you to do it in-place with O(1) space, or they'll ask follow-ups about leading/trailing spaces, or multiple spaces between words. If you freeze on the edge cases during your live OA, StealthCoder surfaces a clean solution in seconds, invisible to the proctor.

Companies asking
24
Difficulty
MEDIUM
Acceptance
52%

Companies that ask "Reverse Words in a String"

If this hits your live OA

Reverse Words in a String 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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The core pattern lives in Two Pointers and string manipulation. You have a string like 'the quick brown fox'. A naive approach: split, reverse, join. But the real test is whether you handle multiple spaces, leading spaces, and trailing spaces correctly. Some candidates overthink and build a new string manually; others try to reverse in-place with two pointers and find themselves tangled in index logic. The gotcha: languages handle trailing whitespace differently, and the problem statement often hides this detail. If your first attempt fails on the whitespace test cases, you're not alone, and you'll waste time re-reading the spec instead of coding. StealthCoder hedges that gap by showing you a working implementation that handles the exact variant your OA is testing, so you can move on without panic.

Pattern tags

The honest play

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

Reverse Words in a String 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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Reverse Words in a String interview FAQ

Do I really need to solve this in O(1) space?+

Depends on your company. Most OAs let you split and rejoin. Some, especially FAANG rounds, push for in-place reversal to test two-pointer skill. Check the problem statement for explicit space constraints. If it says 'in-place', yes. Otherwise, split and join is fine.

What's the trick everyone misses?+

Whitespace. The problem usually says 'multiple spaces between words should be reduced to a single space' or 'leading and trailing spaces should be removed', but it's buried in the description. People code the happy path first, then fail test cases. Read the edge cases twice before you start.

Is this still asked at Visa, HPE, and Snap?+

Yes. It's reported by 24 companies total, including those three. It's common enough that you should know it cold. Not a trick question at big tech anymore, but still a filter for string fundamentals.

How does this connect to Two Pointers?+

Two pointers shine when you reverse in-place. You anchor one pointer at the start, one at the end, and swap characters as you move inward. Same concept applies to reversing words without extra space, so drilling this problem strengthens your two-pointer intuition overall.

What if I blank on the in-place approach during my OA?+

Split and rejoin. It's O(n) space but correct and fast to code. You'll pass most test cases. If the problem explicitly forbids it, or you see a hint about in-place, that's when you pivot. Don't spend 10 minutes stuck; code the obvious path first.

Want the actual problem statement? View "Reverse Words in a String" 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.