Why can the answer be nums.length?

Practice this question from Search Insert Position - Lower bound Pattern Practice Quiz, with options and an explanation.

Question

Why can the answer be nums.length?

Option A — Correct answer

The target belongs after the last element

Option B

The target must be present

Option C

The array is rotated

Option D

The midpoint overflowed

Explanation

If the target is larger than every element, it should be inserted after the last element.

Search Insert Position - Lower bound Pattern Practice Quiz

All questions · Previous question

Open on QuizMaker