First True With Lower Bound
Step by Step
Lower bound keeps the answer inside [lo, hi] and halves the range. Values that are too small move lo past mid, and big enough values pull hi down to mid.
Step through every halving in both directions, then share a link to the step where the range shrank.
What You Watch While the Range Halves
The range, mid and the greyed out half change on every step.
Lower bound finds the first position where a value is big enough. Halving the range gets there in log n checks.
CodeStory's visualiser shows the search range halving and the discarded half greyed out. Marked code lines follow every move, and you can step back, step forward or play.
Open Duplicates of the target first. Then load Target in the middle to see why hi = mid − 1 fails.
How Lower Bound Finds the First True
Steps below follow the range on your screen.
- 1Keep the answer inside a range from lo to hi.
- 2Look at the middle of that range.
- 3Move lo past mid when the value is too small, or pull hi down to mid when it is big enough.
- 4Stop when lo and hi meet. That position is the answer.
Lower Bound Mistakes the Visualiser Shows
A switch in the visualiser turns the mistake on, so you can watch the state go wrong.
- Bug: hi = mid − 1Throws mid away even when nums[mid] ≥ target, so the answer itself can leave [lo, hi]. Load Target in the middle or Duplicates to see it.
Lower Bound Inputs Worth Trying
Five presets cover duplicates, missing targets and both ends of the array.
- Duplicates of the targetFinds the first 5, not just any 5. Switch on the hi = mid − 1 bug here.
- Target in the middleThe very first mid is the answer. Switch on the hi = mid − 1 bug and watch the answer leave.
- Target not in the arrayAnswer is the spot where 7 would be inserted.
- Smaller than alllo never moves, so the answer is 0.
- Larger than allhi never moves, so the answer is n, past the end.
Lower Bound Cost in Time and Space
Halving the range on every check keeps the time at log n.
- Time
- O(log n)counted from the checks you step through
- Space
- O(1)two index values and nothing else
- Pattern
- Binary searchHalve the search range with every check.
Practise Binary Search Beyond Lower Bound
Watching shows the range shrink and solving trains you to define the true condition.
Everything in the App in One Place
Practice, interviews and tools all start free. Swipe to see the rest.
DSA practice
Problems filed under the pattern that solves them, not a sheet.
352 problemsOpenCompany sets
Practise what one company asks in the week before your round.
463 companiesOpenCoding interview
Choose a role, write in a real editor and answer while you type.
scored reportOpenMock interviews, spoken
You answer out loud and CodeStory follows up on what you said.
32 topicsOpenDatabase round
Answer DBMS the way a panel asks it, with indexes, joins and normal forms.
in Core CSOpenOOP round
Inheritance, polymorphism and the follow-up you never rehearse.
in Core CSOpenSystem design
How real systems are built, from the primitives to the AI stack.
27 chaptersOpenSQL practice
Real schemas, your query, the rows it returns and a clear verdict.
39 questionsOpenAptitude
Quant, logical, verbal, DI and technical, timed like the real test.
280 questionsOpenOnline assessment
Get a clock, marks per question and hidden tests like a company's judge.
37 papersOpenAlgorithm visualiser
Watch it play on your own input, one step at a time.
26 algorithmsOpenAI that helps, not solves
Hints one at a time and AI review before a mentor sees your work.
100 free creditsOpenResume builder
Build it inside the app, next to the work you practised.
in the appOpenProgress and readiness
One score and the axis where you are weakest.
tracked dailyOpen
Sign up for 100 AI credits now and get 100 more every month. Start free in the app
Lower Bound Visualiser FAQs
Open the visualiser and follow the range as it halves.
Open the visualiserWhat does the lower bound visualiser show?
CodeStory's visualiser shows the search range halving and the discarded half greyed out, beside the highlighted code. Move back and forth through every step, or let it play.
What is the time complexity of lower bound?
O(log n) time and O(1) space. Live counts show the range halving instead of a formula on a slide.
Why does my lower bound code fail on some inputs?
Setting hi to mid − 1 is a common cause. Switch the bug on in the visualiser and watch the answer leave the range.
Can I use my own input?
Yes. Enter your own input and the visualiser plays the algorithm on it, including the edge cases that break a solution in an interview.
Is the visualiser free?
Yes. Every new account starts with 100 AI credits and gets 100 more monthly, while watching an algorithm costs nothing.
Stuck on Binary Search? Get a Free Callback
Tell CodeStory which binary search step loses you, and a mentor plans what comes next.
- 1CodeStory checks your level, from binary search basics to interview ready.
- 2CodeStory explains online and campus batches, with timings for your weekdays or weekends.
- 3You decide. No pressure, no payment on the call.