Noddy's Examination
EasyP3Coding
An exam has questions in order, difficulty[0], difficulty[1], ... A student starts at the first question and can only solve a question whose difficulty is at most x. The student goes through the paper in order and may skip at most one question that is too hard; meeting a second too-hard question ends the attempt.
Return the number of questions the student solves. The skipped question is not counted.
Example 1
- Input
- difficulty = [1,2,9,3,4], x = 5
- Output
- 4
- Why
- Solve 1 and 2, skip 9, solve 3 and 4: 4 questions.
Example 2
- Input
- difficulty = [9,9,1], x = 5
- Output
- 0
- Why
- The first question is skipped; the second is too hard as well, so the attempt ends with 0 solved.
Example 3
- Input
- difficulty = [1,2,3], x = 5
- Output
- 3
Constraints
- 0 <= difficulty.length <= 10^5
- 1 <= difficulty[i], x <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.