Range cardinality estimate
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.
0:00 of about 22 min
solution.py
InputExpectedGot
[[1,3,3,5,8,8,8,12],3,8]6not run yetsample