Problem solving with programming: Finding the right most occurence of an element in a sorted array
Given an array of sorted numbers, we have to find the right most occurrence of a number.For example given an array {1,2,2,2,3}, the right most occurrence of 2 is at index 3 (0-based index).
This post is related to one of my previous posts ( Finding the left most occurrence in sorted array).
Similar to the above problem, we have to utilize binary search to solve this problem in O( log n ) time. Normal binary search returns any index which matches the given value. So, We have to customize binary search to find the right most instance.
Read full article from Problem solving with programming: Finding the right most occurence of an element in a sorted array
No comments:
Post a Comment