Pressure Chamber Linear Interpolation
Reported by candidates from SpaceX's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
SpaceX reported this one in June 2025, and it looks scarier than it is. Rocket pressure chambers, liftoff, velocity curves. Strip the story and it's a sorted array lookup plus one line of algebra. You get known velocity-to-pressure points and a query velocity, and you return the straight-line pressure between the two neighbors. The only real decision is how you find those neighbors fast on up to 100,000 points. If you blank on the edge cases during the live OA, StealthCoder runs invisibly on your desktop as a safety net. Most candidates won't need it here.
The problem
Pressure Chamber Linear Interpolation A pressure chamber must follow target pressures as a vehicle's velocity changes during liftoff. The reported interview task provides known velocity-to-pressure points and asks for the target pressure at another velocity without introducing a sudden jump. Practice Contract For this exercise, assume velocities and pressures describe aligned known points. The velocities are strictly increasing, and queryVelocity lies between the first and last known velocities, inclusive. If queryVelocity equals a known velocity, return its pressure. Otherwise, find the two neighboring known velocities and return the pressure obtained by linear interpolation between their aligned pressure values. Function interpolateChamberPressure(velocities: double[], pressures: double[], queryVelocity: double) → double Examples Example 1 velocities = [0.0,100.0] pressures = [120.0,300.0] queryVelocity = 50.0 return = 210.0 50 is halfway between velocities 0 and 100, so its pressure is halfway between 120 and 300: 210. Example 2 velocities = [0.0,25.0,70.0] pressures = [100.0,150.0,330.0] queryVelocity = 25.0 return = 150.0 The query exactly matches the second known velocity, so return its aligned pressure 150. Example 3 velocities = [0.0,20.0,50.0] pressures = [100.0,140.0,200.0] queryVelocity = 35.0 return = 170.0 35 is halfway between 20 and 50, so interpolate halfway between pressures 140 and 200. Constraints 2 ≤ velocities.length == pressures.length ≤ 100,000 All input values are finite doubles with absolute value at most 10^9. velocities is strictly increasing. velocities[0] ≤ queryVelocity ≤ velocities[velocities.length - 1] Answers within 10^-6 of the exact interpolated pressure are accepted.
Reported by candidates. Source: FastPrep
Pattern and pitfall
What it really reduces to: binary search on a strictly increasing array, then interpolate. Find the first index where velocities[i] >= query. If velocities[i] equals the query, return pressures[i]. Otherwise use i-1 and i, compute t = (q - v0) / (v1 - v0), and return p0 + t * (p1 - p0). A linear scan passes at this size, but binary search is the clean answer and shows you read the constraints. Pitfalls: the query equal to the first or last velocity, where i-1 could go out of bounds. Handle exact matches first. Also watch precision. Values reach 10^9, so use p0 + t * (p1 - p0), not a form that subtracts large products. The tolerance is 10^-6. If the edge cases tangle you up mid-assessment, StealthCoder is the hedge that reads the problem and hands you the working version.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Pressure Chamber Linear Interpolation 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 passed his OA cold and still thinks the filter is broken.
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 passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Pressure Chamber Linear Interpolation FAQ
What's the trick in the SpaceX Pressure Chamber Linear Interpolation problem?+
Binary search for the neighboring velocities, then apply the linear formula p0 + (q - v0) / (v1 - v0) * (p1 - p0). The array is strictly increasing, so the search is safe and there's no division by zero between neighbors.
How hard is this OA question really?+
Easy. It's mostly a story wrapped around lower_bound and one formula. The difficulty is in the details: exact matches, endpoints, and floating point accuracy. If you've written a binary search before, you can finish it quickly.
Do I need binary search or is a linear scan fine?+
With up to 100,000 points, a single linear scan runs fine. Binary search in O(log n) is still the better answer and costs almost nothing extra. Use the built-in bound function if your language has one, and handle exact matches first.
What edge cases should I test?+
Query equal to the first velocity, query equal to the last velocity, and a query equal to a middle point. Also test two-point arrays and decreasing pressures, where the slope is negative. Large values near 10^9 are worth a quick check for precision.
How do I prepare for this in 48 hours?+
Write binary search for the first index with value >= target until you can do it without off-by-one errors. Then practice interpolation on three or four hand-made examples. Reported in June 2025 at SpaceX, the problem is small, so your prep should be too.