Recent Four Unique
Last four must be unique
Recent 4 Unique Elements
Problem Statement
Given a stream of 100 integers, ensure that in any window of 4 consecutive elements, all 4 values are unique (no duplicates).
All values are in the range 0, 1000.
Constraints
- Stream length: 100 elements
- Element range: 0 ≤ element ≤ 1000
- Uniqueness window: last 4 elements must all be different
Examples
Example 1:
[1, 2, 3, 4, 5, 6, 7, 8, ...]
Valid
Explanation: Each 4-element window has unique values
- Window [0:3]: [1, 2, 3, 4] → all unique
- Window [1:4]: [2, 3, 4, 5] → all unique
- Window [2:5]: [3, 4, 5, 6] → all uniqueExample 2:
[1, 2, 3, 1, 5, 6, 7, 8, ...]
Invalid
Explanation: At position 3, value is 1 which equals stream[0]
- Window [0:3]: [1, 2, 3, 1] → 1 appears twice!Example 3:
[10, 20, 30, 40, 10, 50, 60, 70, ...]
Valid
Explanation: At position 4, value is 10 which equals stream[0]
- Window [3:0]: [10, 20, 30, 40] → all unique ✓
- Window [7:4]: [10, 50, 60, 70] → all unique ✓Example 4:
[0, 1, 2, 3, 0, 1, 2, 3, ...]
Valid
Explanation:
- Position 4: stream[4]=0 ≠ stream[3]=3, ≠ stream[2]=2, ≠ stream[1]=1 ✓
- Position 5: stream[5]=1 ≠ stream[4]=0, ≠ stream[3]=3, ≠ stream[2]=2 ✓
- Pattern repeats and satisfies the constraintLoading the interactive workspace...