Leetcode 34 -> Find First and Last Position of Element in Sorted Array
We use the modified binary search here, when we find the element we don’t break our binary search, instead we keep on moving, One time towards left and another time towards the right to find the left most and right most index of our target. The below code illustrates the approach more clearly.
|
|