DebugJuniorBackendAuto-graded
Fix a search that returns the wrong index
Make two binary searches return the first and last index of a value in a sorted list with duplicates, or -1 if it's missing.search.py has two binary searches over a sorted list that may contain duplicates. find_first should return the index of the first occurrence of a value and find_last the last one, with -1 when the value isn't there. Callers report wrong indices on repeated values, calls that never return, and an index for values that aren't in the list. Fix both and keep them O(log n): no linear scan, list.index, list.count or bisect.20 min
python
You're done when
find_firstalways returns the leftmost index of the target, even inside a run of duplicates.find_lastalways returns the rightmost index of the target.- Both return -1 when the target isn't in the list or the list is empty.
- Neither function hangs, whatever the input.
- Both are still binary searches: a linear scan,
list.index,list.countorbisectdoesn't count.
What it measures
Search boundariesWhether the search lands on the first or last match in duplicate runs and at both ends of the list.
DebuggingHow you get from a few wrong answers and a hang to the cause, and how you check the fix on edge cases.
Working to a constraintKeeping the fix inside an O(log n) binary search.
Your environment
Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards
Start this lab
20 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo