Ctrl K

Missing After the Opening Run

Easy
You get an integer array values. Call its *opening run* the longest prefix in which each number is exactly 1 more than the one before it. The first element on its own also counts as a run. Let s be the sum of the opening run. Return the smallest integer that is at least s and does not appear in values.
Example 1
values=[4, 5, 6, 9, 15, 16] → 17

The opening run is 4, 5, 6 with a sum of 15. Both 15 and 16 are in the array, 17 is not.

Example 2
values=[2, 7, 3] → 4

The run is just the 2. Both 2 and 3 are present, but 4 is missing.

Example 3
values=[1, 2, 3, 4] → 10
Constraints
  • 1 ≤ len(values) ≤ 50
  • 1 ≤ values[i] ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyDoes Any Value Repeat EasyThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats Easy
loading Python…
Input
values=[4, 5, 6, 9, 15, 16]
Expected
17

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