Google L4 Phone screening

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-09-01Added By Anonymous
Source: Link

Company: Google
Role: L4
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

You are given a stream of integers arriving one by one, and an integer d. At any time, you may form a triplet of numbers from the stream if the difference between the maximum and minimum of the three numbers is at most d. Once a triplet is formed, those three numbers must be immediately removed from memory and cannot be reused in any other triplet.

Design a data structure that processes the stream online:

When a new number arrives, insert it into memory.

If any valid triplet can be formed, remove it immediately and return it.

Continue this process for the entire stream.

Comments