FastPrepStreamed Scalar Item Triplets
Problems/Streamed Scalar Item Triplets

Streamed Scalar Item Triplets

Google logoGoogle● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Google AI/ML interview report describes item sizes that arrive one at a time. A group is returned as soon as three items have a max minus min strictly below a threshold. It also mentions unsorted arrivals and sorted insertion. This finite batch version shows the reported streaming behavior. We chose the item IDs, how groups are used up, how ties are picked, and the input limits. Our version is about 82% the same as the reported question.

Items arrive one at a time on a belt. arrivals[i] is the integer size of item ID i. Equal sizes still represent separate items.

Keep unconsumed items. Immediately after each arrival, if any three available items satisfy max(size) - min(size) < threshold, package exactly one triple and remove those items from future consideration. A difference equal to the threshold does not qualify.

To make the answer unique, sort the available items by (size, item ID). Pick the first group of three neighbors in that order that qualifies, and return its three item IDs in increasing ID order. If none qualifies, return an empty row for that arrival. At most one group can form per arrival because before the arrival no valid triple existed.

Return one row for every arrival. Treat the arrivals as one call after another: you may not use a later item early, and items left unmatched at the end are not packaged. If threshold is zero, no triple qualifies.

Function

packageScalarArrivals(arrivals: int[], threshold: int) → int[][]

Examples

Example 1

arrivals = [5,8,6,7]threshold = 3return = [[],[],[],[0,2,3]]

The first three items have range 3, so they do not fit. Item 3 creates the qualifying sizes 5, 6, 7, whose IDs are [0,2,3].

Example 2

arrivals = [9,1,3,2,10,11]threshold = 3return = [[],[],[],[1,2,3],[],[0,4,5]]

When item 3 arrives, sizes 1, 2, 3 form a package with IDs [1,2,3]. After item 5 arrives, the remaining sizes 9, 10, 11 form a second package.

Example 3

arrivals = [4,4,4,4]threshold = 1return = [[],[],[0,1,2],[]]

The first three distinct items of size 4 form one package. The fourth item remains unpaired.

Constraints

  • 0 <= arrivals.length <= 100.
  • -10^6 <= arrivals[i] <= 10^6.
  • 0 <= threshold <= 10^6.
  • Arrival order may be arbitrary, and duplicate sizes are allowed.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
  • Deterministic Secret Santa AssignmentShopify · PHONE SCREENShopify interview questions
  • Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
  • Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions
  • Longest Uninterrupted Work BlockIntuit · PHONE SCREENIntuit interview questions
  • Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
  • Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Bus Station Seat AllotmentInMobi · PHONE SCREENInMobi interview questions

Interview reports that mention this question

  • Google New Grad SWE Interview Questions Guide (Part 1 of 2)
  • Google MLE IC4 PhD New Grad Offer: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] packageScalarArrivals(int[] arrivals, int threshold) {
        // Write your code here.
    }
}
Checking account…