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 (12)


