Skip to content

ORIGINAL CODING QUESTION

Find the first available slot

Given sorted availability scores, return the zero-based index of the first score at least the target. Return n if none qualifies.

Open practice workspace

Original exercise · medium. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n sorted nondecreasing scores, then target. Print an index.

Constraints

1 ≤ n ≤ 10,000; scores and target between -100,000 and 100,000.

Example 1

Input

5
1 3 3 7 9
3

Output

1

The first score at least 3 is at index 1.

Example 2

Input

3
2 4 6
8

Output

3

No score qualifies; return n = 3.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Use a half-open search interval.

Hint 2

Keep the answer inside [left, right); equal values move the right boundary.

Hint 3

If a[mid] < target, set left = mid + 1; otherwise right = mid.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →