Ctrl K

Seen in a Single Window

Easy
You get an integer array values and a window width width. A window is any contiguous stretch of the array that is exactly width elements long. Call a number *lonely* if it appears in exactly one window (how many times it repeats inside that window does not matter). Return the largest lonely number, or -1 if there is none.
Example 1
values=[6, 2, 8, 4, 5], width=2 → 6

The windows are [6, 2], [2, 8], [8, 4], [4, 5]. Only 6 and 5, the numbers at the ends, show up in exactly one window; the larger one is 6.

Example 2
values=[4, 7, 1, 4], width=3 → -1

The windows are [4, 7, 1] and [7, 1, 4]. 4 is in both, and so are 7 and 1, so no value qualifies.

Example 3
values=[3, 3, 9], width=1 → 9
Constraints
  • 1 ≤ len(values) ≤ 50
  • 0 ≤ values[i] ≤ 50
  • 1 ≤ width ≤ len(values)
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
values=[6, 2, 8, 4, 5], width=2
Expected
6

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