Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Find First and Last Position of Element

Medium Binary Search

Given a sorted array and a target, print the first and last index at which target appears. Print -1 -1 if the target is absent. The solution must run in O(log n).

Constraints

0 <= n <= 10^5 -10^9 <= nums[i], target <= 10^9

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.