← Back to Hub

✨ Rightmost Rune Quest

Find the Last Occurrence in Sorted Array

Target

-

Best Candidate

None

Current Mid

-

Search Range

-

Steps

0
🧠 Current Logic
Generate an array to begin your quest!
Key Insight: When arr[mid] == target, we found a match but there might be a later occurrence. So we save this as our candidate answer and keep searching RIGHT!
✨ The Golden Rune Array ✨
Left: -
Mid: -
Right: -
Answer: -
Generate an array to start your quest for the rightmost rune!

πŸ“– Last Occurrence Algorithm

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)