~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Sorted containers (bisect)
Ordered-set operations in Python: bisect.insort, floor/ceiling lookups.
Main path: 8 problems, about 4 hours.
Notes
Recognise it when: you need an ordered set or map with inserts plus "floor / ceiling / previous / next" queries: calendars, leaderboards, the nearest element.
import bisect
starts = [] # keep sorted
i = bisect.bisect_right(starts, x) # floor = starts[i-1], ceiling = starts[i]
bisect.insort(starts, x) # O(n) insert, but fast in practice
sortedcontainers.SortedListgives O(log n) inserts, but it's not in the standard library and may not be allowed. Know the bisect fallback.- Calendar booking: find the neighbours around the new start and check that they don't overlap.
Gotchas: keep parallel lists in sync, or store tuples. insort is O(n), which is fine up to about 10^5 operations.
12 problems
Interview roadmap
Binary search Sorted lookups, rotations, searching the answer.
Sorted containers (bisect) guide
- Play first: The Server Ring 1-minute game Consistent hashing
- Floor and ceiling with bisect basics py · c++ · java easy
- Nearest free parking spot py · c++ · java easy
- Consistent Hashing code the boss py · c++ · java medium
- My Calendar I py · c++ · java medium
- Stock price with corrections py · c++ · java medium
- Concert tickets: best ticket under a budget py · c++ · java medium
- Data Stream as Disjoint Intervals py · c++ · java hard
- Game leaderboard assessment 3 levels py · c++ · java medium
More practice: 4 problems
- Customer revenue system assessment 2 levels Databricks py · c++ · java medium
- Top k pins assessment 2 levels Pinterest py · c++ · java medium
- Spreading keys over a ring of servers assessment 3 levels py · c++ · java medium
- Memory allocator assessment 3 levels OpenAI py · c++ · java hard