Remove repeated tracks entirely: hints, no solution
Medium · Linked list
A radio queue is sorted by track id, so tracks that share an id sit next to each other. The station wants to keep only tracks whose id appears exactly once in the queue. If an id appears two or more times, remove every copy of it, not just the extras.
The queue is given as a sorted array from head to tail. Return what remains, still sorted, as an array. If nothing is unique, return an empty array. In a linked list the head itself may be one of the removed runs, which is the usual pitfall.
Examples
- Input
- queue = [1, 2, 2, 3, 4, 4, 4, 5]
- Output
- [1, 3, 5]
- Note
- Ids 2 and 4 occur more than once, so all their copies are removed, leaving 1, 3 and 5.
- Input
- queue = [7, 7, 7]
- Output
- []
- Note
- One id fills the whole queue, so nothing survives.
Constraints
- 0 <= queue.length <= 190000
- 0 <= queue[i] <= 999999
- queue is sorted in non-decreasing order
Hint 1: a nudge
When you are standing on a track, what do you need to know about its neighbours to decide if it is the only one with its id?
Unlock the full hints and timed practice with a pass
The second and third hints and the timed, runner-checked practice are part of a pass.