Reach a Number
A medium-tier problem at 44% community acceptance, tagged with Math, Binary Search. Reported in interviews at InMobi and 1 others.
Reach a Number is a medium-difficulty problem that's been asked at InMobi and Commvault. You're given a target integer and need to figure out the minimum number of steps to reach it, where each step you can either add or subtract a sequentially increasing value (1, then 2, then 3, and so on). The math trick isn't obvious on first read, which is why 44% of submissions pass. Most candidates either brute-force a BFS or struggle with overflow. If this lands in your live assessment and the greedy intuition fails, StealthCoder runs invisibly and surfaces the pattern in seconds.
Companies that ask "Reach a Number"
Reach a Number 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 by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe trap is thinking you need to simulate every possible path. You don't. The key insight is that you can always reach any number by adding 1, 2, 3,..., n (which sums to n*(n+1)/2), then deciding which terms to flip from addition to subtraction. This becomes a partition problem: can you subtract a subset that changes the sum to your target? Use math to find the minimum n where the total sum and your target have the same parity, then binary search handles the boundary cases cleanly. Most candidates time out on brute force or miss the parity condition entirely. Once you see it, the code is short. StealthCoder is your hedge if the pattern doesn't click under live pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Reach a Number 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 by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Reach a Number interview FAQ
Is this really a math problem or a search problem?+
Both. The topics list shows Math and Binary Search for a reason. You need the mathematical insight (parity and sum formulas) to reduce the problem space, then binary search to find the exact threshold. Skip the math and you're doing exponential work.
What's the obvious wrong approach?+
BFS from 0 to target, exploring every add and subtract at each step. It works for tiny targets but blows up in memory and time. The problem expects you to think algebraically, not just explore the tree.
How often does this show up in real assessments?+
Lower frequency overall, but it's been asked at InMobi and Commvault. It's the kind of problem that separates candidates who can think mathematically from those who only know standard graph algorithms. If your target company uses it, you need this pattern locked in.
Does binary search complexity matter here?+
Yes. You're not searching the answer space linearly. Binary search bounds your iterations to roughly O(log n) where n is derived from the target and parity constraint. Without it, you're checking every possible sequence length manually.
What if I see this and don't remember the trick?+
The parity insight is the gatekeeper. If target and sum have different parity, no valid path exists with current n. Increment n until they match, then verify with binary search. It's not complex once named, but it's easy to blank on during interview pressure.
Want the actual problem statement? View "Reach a Number" on LeetCode →