Ctrl K

Trim the Front Until Unique

Easy
You are given an integer array queue. One operation deletes three elements from the front of the array, or all of the remaining ones if fewer than three are left. Return the smallest number of operations after which no value appears in the array more than once. An empty array has no repeats.
Example 1
queue=[5, 1, 5, 2, 8, 3, 2] → 2

After the first cut [2, 8, 3, 2] is left and 2 repeats. After the second only [2] is left, with no repeats.

Example 2
queue=[9, 9] → 1

One cut removes both items; an empty list has no repeats.

Example 3
queue=[4, 7, 1] → 0

There are no repeats to begin with.

Constraints
  • 1 ≤ len(queue) ≤ 100
  • 1 ≤ queue[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyRepeat Within Reach EasyThe Lost Ticket Easy
loading Python…
Input
queue=[5, 1, 5, 2, 8, 3, 2]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.