Drop skipped tracks: hints, no solution

Easy · Linked list

A listener has marked some tracks as skipped, and the player must remove every queue entry whose id is on that skip list. The queue is given as an array of ids from head to tail, and a track id can appear in it more than once.

Return the queue after removal: every entry whose id is not in the skip list, in the same relative order as before. The skip list may repeat ids and may be empty. If nothing is left, return an empty array.

In a real linked list you would unlink nodes as you pass them, and the head itself can be removed, so take care with that first entry.

Examples

Input
queue = [4, 7, 4, 9, 2], skip = [4, 2]
Output
[7, 9]
Note
The entries 4, 4 and 2 are removed, leaving 7 and 9 in order.
Input
queue = [1, 2, 3], skip = []
Output
[1, 2, 3]
Note
Both entries carry the skipped id, so the result is empty.

Constraints

  • 0 <= queue.length <= 130000
  • 0 <= skip.length <= 100000
  • 0 <= queue[i], skip[j] <= 999999

Hint 1: a nudge

For each entry, what single question decides whether it stays? How could you answer it quickly if the skip list were long?

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.

See pricing

Sign in

Check my resume first