~/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.
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.
11 problems
Interview roadmap
Binary search Sorted lookups, rotations, searching the answer.
Sorted containers (bisect) guide
- Basics: floor and ceiling with bisect basics py · c++ · java easy
- Nearest free parking spot py · c++ · java easy
- My Calendar I py · c++ · java medium
- Stock price with corrections py · c++ · java medium
- Data Stream as Disjoint Intervals py · c++ · java medium
- Concert tickets: best ticket under a budget py · c++ · java medium
- OA: Memory allocator 3 levels OpenAI hard
- OA: Customer revenue system 2 levels Databricks py · c++ · java medium
- OA: Top k pins 2 levels Pinterest py · c++ · java medium
- OA: Game leaderboard 3 levels py · c++ · java medium
- OA: Spreading keys over a ring of servers 3 levels py · c++ · java medium