FastPrepStreaming Triple Packing by Size Threshold
Problems/Streaming Triple Packing by Size Threshold

Streaming Triple Packing by Size Threshold

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives item sizes arriving one at a time, a stateful class, a strict max-minus-min threshold for three items, immediate output of a triple, sorted insertion, and checking an adjacent window. We chose to remove items after packing, a fixed pick among several triples, a finite batch interface, the examples, and the input limits. The follow-up with two-dimensional Euclidean distance stays blocked, because its exact rules and output were not kept. Our one-dimensional version is about 88% the same as the reported question.

Items arrive on a conveyor belt one at a time. sizes[i] is the nonnegative integer size of the next item.

Keep every unpacked item. After each arrival, if three unpacked sizes a <= b <= c satisfy c - a < threshold, immediately pack and remove one such triple.

When more than one triple is possible, choose the lexicographically smallest sorted triple. Return every packed triple, with each triple sorted, in the order it is packed. Items left unpacked after the final arrival are not returned.

Function

packTriples(sizes: int[], threshold: int) → int[][]

Examples

Example 1

sizes = [5,1,4,3,9,2]threshold = 3return = [[3,4,5]]

After size 3 arrives, the sorted available sizes are [1,3,4,5]. Triple [3,4,5] has range 2, which is strictly below 3, so it is packed. The remaining values never form another valid triple.

Example 2

sizes = [1,2,3,10,11,12]threshold = 3return = [[1,2,3],[10,11,12]]

Each consecutive block of three has range 2 and is packed as soon as its third item arrives.

Example 3

sizes = [0,10,20,11]threshold = 15return = [[0,10,11]]

When 11 arrives, both [0,10,11] and [10,11,20] are valid. The lexicographically smaller triple [0,10,11] is chosen.

Constraints

  • 1 <= sizes.length <= 5000.
  • 0 <= sizes[i] <= 1000000000.
  • 1 <= threshold <= 1000000000.

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

  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Maximize the Minimum Distance Between RobotsAmazon · ONSITE INTERVIEW
  • Maximum Total Length of Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Room Occupancy at Query TimesWhatNot · ONSITE INTERVIEWWhatNot interview questions
  • HTTP Log QueriesDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Smallest Common Integer in Sorted ListsMotive · ONSITE INTERVIEWMotive interview questions
  • Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
  • Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
  • Count Later Lower ReadingsRippling · ONSITE INTERVIEWRippling interview questions
  • Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions

Interview reports that mention this question

  • Google PhD Early Career ML Loop With Extra Round: 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
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] packTriples(int[] sizes, int threshold) {
        // write your code here
    }
}
Checking account…