Ctrl K

Windows With Every Value

Medium
You get an array of positive integers values. Call a contiguous non-empty window of the array **full** if it contains every distinct value that occurs anywhere in the array. Return the number of full windows.
Example 1
values=[4, 9, 4, 4] → 5

There are two distinct values, 4 and 9. Both appear in [4, 9], [4, 9, 4], [4, 9, 4, 4], [9, 4] and [9, 4, 4]: 5 windows.

Example 2
values=[6, 6, 6] → 6

There is only one value, so each of the 6 non-empty windows qualifies.

Example 3
values=[1, 2, 3] → 1
Constraints
  • 1 ≤ len(values) ≤ 1000
  • 1 ≤ values[i] ≤ 2000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo-Genre Stretch of a Playlist MediumWindows With an Exact Alarm Count MediumStretches With k Odd Numbers MediumTwo Separate Segments With a Given Sum MediumTrim the Ends to a Target Medium
loading Python…
Input
values=[4, 9, 4, 4]
Expected
5

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