← Binary Search

Pattern Recognition Drill

#52 — Find insert position

Easy Binary Search

The Problem

Given a sorted array and a target, return the index where the target would be inserted.

What approach would you use?

Think about it before scrolling down.

Key Signals

Binary Search

Standard binary search but return lo when not found. lo always points to the insert position. O(log n).

Common Trap

This is bisect_left. Know the difference between bisect_left and bisect_right.

← #51 #53 →