DEV Community

xscoox
xscoox

Posted on

๐Ÿš€Day 1 of #100DaysOfCode - Upper Bound with Binary Search in TypeScript

Today, I explored an important variation of binary search-the upper bound function. This is useful when we need to find the first element greater than a given value in a sorted array.

๐Ÿ”ท What is Upper Bound?
The upper bound of a target in a sorted array is the smallest index where an element greater than the target exists. If no such element exists, it returns the array length.

โš’๏ธ Implementing Upper Bound in
TypeScript

Here's my TypeScript implementation using binary search:

Image description

๐Ÿ“Œ What I Learned Today

โœ… Upper Bound is useful for range queries, insertion positions, and ordered datasets.
โœ… Binary Search makes it efficient with
O(log n) time complexity.
โœ… Edge Cases are important, like when all
elements are โ‰ค target.

Feeling great about today's progress! Excited for more learning ahead ๐Ÿ’ก๐Ÿ”ฅ

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.