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 πŸ’‘πŸ”₯

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more