Speed to Pressure Lookup
Reported by candidates from SpaceX's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The SpaceX OA reported in March 2025 looks like a physics story, but it's a floor lookup in disguise. Given sorted speed breakpoints, find the greatest one that's less than or equal to the input speed and return its pressure. That's binary search on a sorted array. If you've got an invite for this one, the whole question is whether you write the boundary condition cleanly. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but the pattern here is small enough to own tonight.
The problem
Speed to Pressure Lookup Write an algorithm that receives a speed and returns the corresponding pressure. Each speed interval uses the pressure associated with the smaller endpoint. For example, every speed from 0 up to, but not including, the next listed speed uses the pressure associated with 0. The source notes that the lookup values are not guaranteed to remain hard-coded. Practice Contract For this exercise, assume speedBreakpoints is a strictly increasing list whose first value is 0, and pressures[i] is the pressure that begins at speedBreakpoints[i]. Return the pressure at the greatest breakpoint that is less than or equal to speed. A speed equal to a breakpoint uses that breakpoint's pressure. A speed above the final breakpoint uses the final pressure. Function lookupPressure(speedBreakpoints: int[], pressures: int[], speed: int) → int Examples Example 1 speedBreakpoints = [0,10,20,30] pressures = [100,95,80,60] speed = 7 return = 100 The greatest breakpoint not exceeding 7 is 0, so the answer is pressures[0] = 100. Example 2 speedBreakpoints = [0,10,20,30] pressures = [100,95,80,60] speed = 10 return = 95 A speed equal to a breakpoint uses that breakpoint's pressure, so 10 maps to 95. Example 3 speedBreakpoints = [0,10,20,30] pressures = [100,95,80,60] speed = 99 return = 60 The speed is above the final breakpoint, so the final pressure applies. Constraints 1 ≤ speedBreakpoints.length == pressures.length ≤ 100,000 speedBreakpoints[0] == 0 0 ≤ speedBreakpoints[i] ≤ 10^9 speedBreakpoints is strictly increasing. -10^9 ≤ pressures[i] ≤ 10^9 0 ≤ speed ≤ 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
What it really reduces to: find the rightmost index i where speedBreakpoints[i] <= speed, then return pressures[i]. The array is strictly increasing and starts at 0, so a valid answer always exists. Use binary search with lo=0, hi=n-1. When mid's breakpoint is <= speed, save mid as the answer and move lo up. Otherwise move hi down. That's O(log n) and handles the 100,000 length easily. The common pitfall is a linear scan, which works but looks weak given the note that the lookup values won't stay hard-coded. Another trap is an off-by-one at an exact breakpoint, where speed 10 must return 95, not 100. Speeds above the last breakpoint should land on the final index automatically. If you freeze on the boundary logic during the live OA, StealthCoder is the hedge that hands you the pattern.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Speed to Pressure Lookup cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass SpaceX's OA.
SpaceX reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Speed to Pressure Lookup FAQ
What's the trick in the SpaceX Speed to Pressure Lookup question?+
It's a floor search. Find the greatest breakpoint that's less than or equal to the speed, then return the pressure at that index. Binary search does it in O(log n). Once you see it as a rightmost-less-or-equal lookup, the code is about ten lines.
How hard is this problem really?+
Easy to medium. The idea is simple, but binary search boundaries trip people up under time pressure. Test your loop against the three examples, especially speed equal to a breakpoint and speed above the last one.
Can I just loop through the breakpoints instead?+
A linear scan passes with n up to 100,000 for a single query. But the problem hints the lookup data may change and be reused, so binary search is the answer an interviewer expects. Mention the O(log n) tradeoff if asked.
Is there a built-in function that does this?+
Yes, most languages have a bisect or upper-bound helper. In Python, bisect_right(breakpoints, speed) - 1 gives the index. Check whether the assessment allows library calls, and know how to hand-write the search in case it doesn't.
How do I prepare for this in 48 hours?+
Write a rightmost-less-or-equal binary search from scratch twice. Run the three examples plus edge cases: speed 0, speed equal to the last breakpoint, and a single-element array. That covers nearly every way this question can break.