As reported: Rubrik L4 software engineer loop (2025), algo coding round (medium-hard).
Integers arrive as a stream. After each new item, return the minimum absolute difference between any two elements among the last K elements of the stream (the new item included).
If the window holds fewer than two elements, return -1 for that item.
Example 1
stream = [1,10,4,7,20,21], K = 3 -> [-1,9,3,3,3,1]
Windows: [1], [1,10], [1,10,4] (4−1), [10,4,7] (7−4), [4,7,20] (7−4), [7,20,21] (21−20).
Example 2
stream = [5,5,9], K = 2 -> [-1,0,4]
Constraints: 1 ≤ stream.length ≤ 10^5; 1 ≤ K ≤ 10^5; −10^9 ≤ value ≤ 10^9.
Code runner format: two lines — stream as a JSON array and K. Implement minDifferences(stream, k); the harness prints the list of answers, one per item.