Module 2 · Binary Search · Binary Search Introduction

Search insert position

Values before the answer are smaller than the target and the rest are not: false, …, true. The same Range finds the first index whose value is >= target, halving the candidates at every step.

In the numbered examples nums has one more slot, index n, where a target bigger than everything goes.

Search