Trim a Telemetry Buffer to a Target Sum
Updated
Problem statement
An embedded device stores positive sensor readings in readings. In one operation, it may permanently remove either the oldest reading at the left end or the newest reading at the right end.
Return the minimum number of operations whose removed values sum to exactly x. Return -1 when no sequence of endpoint removals reaches exactly x.
Function
minTelemetryRemovals(readings: int[], x: int) → intExamples
Example 1
readings = [1,1,4,2,3]x = 5return = 2Remove 3 and then 2 from the right end.
Example 2
readings = [5,6,7,8,9]x = 4return = -1No combination of removals from the two ends totals 4.
Example 3
readings = [3,2,20,1,1,3]x = 10return = 5Keeping only the middle value 20 removes a total of 10 using five endpoint operations.
Constraints
1 <= readings.length <= 1000001 <= readings[i] <= 100001 <= x <= 1000000000
Source note: The source image is a source-neutral excerpt of the author-reported prompt, including the preserved conflicting numeric answer.
More Amazon Onsite Interview questions
- Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
- Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Count Hotspot Playback WindowsGoogle · ONSITE INTERVIEWGoogle interview questions
- Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia interview questions
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Max Consecutive Ones IIINykaa · PHONE SCREENNykaa interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)