Find the Last Occurrence in Sorted Array
Problem: Given a sorted array with duplicates, find
the LAST index where target appears.
Key Modification: When
arr[mid] == target, don't stop! Save mid as potential
answer and search RIGHT (left = mid + 1).
Why it works: By continuing to search right even after finding a match, we ensure we find the rightmost occurrence.
Time Complexity: O(log n)