← Back to Hub

πŸͺœ Ceiling Stairway

Find the Upper Bound (First Element > Target)

Target Value

-

Current Mid

-

Search Range

-

Upper Bound

?

Steps

0
🎯 The Difference
Lower Bound
arr[i] β‰₯ target
Upper Bound
arr[i] > target
Find first element STRICTLY GREATER than target
πŸͺœ Climb to the Ceiling πŸͺœ
Left: -
Mid: -
Right: -
Answer: -
Generate an array to find the upper bound!

πŸ“– Upper Bound Algorithm

Problem: Find the smallest index where arr[i] > target (strictly greater).

Logic:

β€’ If arr[mid] > target: This could be our answer, save it and search LEFT.

β€’ If arr[mid] ≀ target: Too small or equal, search RIGHT.

Key Difference from Lower Bound: Uses > instead of β‰₯

Time Complexity: O(log n)