FastPrepTrack Package Receipt Gaps
Problems/Track Package Receipt Gaps

Track Package Receipt Gaps

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time phone screen. The report describes receiving package IDs out of order, and reporting the longest continuous run from zero along with the missing IDs. It does not say how to write the report, what to do with duplicates, what an empty state looks like, or how big the output can be. Our version is about 88% the same as the reported question.

Process a finite sequence of package-receipt operations. Each row of operations has one of these forms:

  • ["receive", packageId] records the nonnegative package ID written as a decimal string. Receiving the same ID again has no additional effect.
  • ["report"] produces one snapshot of the received IDs.

For a report, let maxReceived be the largest received ID, or -1 when no package has been received. Let prefixEnd be the largest value such that every ID from 0 through prefixEnd has been received. If ID 0 has not been received, prefixEnd is -1.

Encode each report as [prefixEnd, maxReceived, missingId1, missingId2, ...], where the missing IDs are every absent value from 0 through maxReceived in increasing order. Thus, an empty state produces [-1, -1]. Return the report rows in operation order.

Function

packageReceiptReports(operations: String[][]) → int[][]

Examples

Example 1

operations = [["receive","2"],["receive","0"],["report"],["receive","1"],["report"]]return = [[0,2,1],[2,2]]

At the first report, IDs 0 and 2 have arrived. The contiguous prefix ends at 0, the maximum is 2, and ID 1 is missing. After receiving ID 1, the complete prefix ends at 2 and there are no gaps.

Example 2

operations = [["report"],["receive","3"],["receive","3"],["report"],["receive","0"],["report"]]return = [[-1,-1],[-1,3,0,1,2],[0,3,1,2]]

The first report observes no packages. Receiving ID 3 twice records it once. After ID 0 arrives, the contiguous prefix advances to 0, while IDs 1 and 2 remain missing.

Constraints

  • 1 <= operations.length <= 100000.
  • Every operation is either ["receive", packageId] or ["report"].
  • Every package ID is a decimal string with no leading zeros for an integer in [0, 200000].
  • The total number of integers across all returned report rows is at most 200000.
  • Operations are applied strictly from left to right.

More Amazon Phone Screen questions

  • Course SchedulePHONE SCREEN · ONSITE 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
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Role-Based Network Access ControlOkta · PHONE SCREENOkta interview questions
  • Transformer KV Cache OperationsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Rate Limiter with Hourly and Daily Effort QuotasZscaler · PHONE SCREENZscaler interview questions
  • Chatter Message WindowReddit · PHONE SCREENReddit interview questions
  • Versioned Recipe Shopping CartDecagon · PHONE SCREENDecagon interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions

Interview reports that mention this question

  • Amazon Experienced Hire OA and Interviews: 21 Experiences

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)
See Amazon hiring insights
Saved
class Solution {
    public int[][] packageReceiptReports(String[][] operations) {
        // Write your code here.
    }
}
Checking account…