2dbi
Home/Dell Technologies/Binary Search (and Variants)
DDell Technologies·DSASDE-1Online Assessment

Binary Search (and Variants)

Problem

Implement binary search; then find the first/last occurrence of a target in a sorted array with duplicates.

Example

[1,2,2,2,3], target=2 -> first=1, last=3

Constraints

  • 1 ≤ n ≤ 10^5

Approach

Lower/upper bound variants; be careful with the mid and boundary updates.

added 6 days ago
LeadersAccount