Speed to Pressure Lookup
Updated
Problem statement
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.
Function 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) → intExamples
Example 1
speedBreakpoints = [0,10,20,30]pressures = [100,95,80,60]speed = 7return = 100The 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 = 10return = 95A 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 = 99return = 60The speed is above the final breakpoint, so the final pressure applies.
Constraints
1 ≤ speedBreakpoints.length == pressures.length ≤ 100,000speedBreakpoints[0] == 00 ≤ speedBreakpoints[i] ≤ 10^9speedBreakpointsis strictly increasing.-10^9 ≤ pressures[i] ≤ 10^90 ≤ speed ≤ 10^9
More SpaceX interview questions
- Starlink Beam PlannerOA · PHONE SCREEN · Seen Nov 2026
- Timestamped Telemetry Stream DifferencesPHONE SCREEN · Seen Sep 2026
- Number of IslandsPHONE SCREEN · Seen Aug 2026
- Number of Islands IIPHONE SCREEN · Seen Aug 2026
- Button Combination DetectorPHONE SCREEN · Seen Feb 2026
- Pressure Chamber Linear InterpolationPHONE SCREEN · Seen Jun 2025
- Simplified Time-Based Key-Value StorePHONE SCREEN · Seen Nov 2023
- Rocket Component CostONSITE INTERVIEW · Seen Aug 2025
- DNA Sequence MatchOA · Seen Apr 2025
- Find the Duplicate NumberONSITE INTERVIEW · Seen Jan 2021
Similar questions at other companies
- First Element Greater Than KMeta · PHONE SCREENMeta interview questions
- Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Price at Query TimestampsGoogle · PHONE SCREENGoogle interview questions
- First Missing Number in a Consecutive ArrayArista Networks · OA · PHONE SCREENArista Networks interview questions
- Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
- Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Leftmost Binary Search MatchByteDance · PHONE SCREENByteDance interview questions
- Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
- Find the First Target IndexSuperhuman · PHONE SCREENSuperhuman interview questions
- First Target IndexGrammarly · PHONE SCREEN