Kth Missing Positive Number
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given arr, a strictly increasing array of positive integers, and an integer k.
Consider the positive integers 1, 2, 3, ... that do not appear in arr. Return the k-th of them (1-indexed). The answer may be larger than every element of arr.
A linear scan is fine; try for O(log n) using how many numbers are missing before each index.
Examples
Constraints
- 1 <= arr.length <= 1000
- 1 <= arr[i] <= 1000
- 1 <= k <= 1000
- `arr[i] < arr[j]` for all `i < j`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.