Code Room
CodingMedium
Question
A B-tree index stores integer keys in sorted order (duplicates allowed). Implement a range-scan cardinality estimate that returns the exact count of index entries with key in the inclusive range [lo, hi]. The keys are given already sorted ascending. You must run in O(log n) — do NOT linearly scan. If lo > hi, return 0. Up to 200000 keys.
Implement
index_range_count(keys: list[int], lo: int, hi: int) → intExamples
in
[[1,3,3,5,8,8,8,12],3,8]out6What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.