Trees & Ordered Maps Hard
TreeMap Range Queries
Follow the source's TreeMap from exact birthday strings to insertion-ordered lists of distinct Person objects.
Trace input
Bounded JSONEdit the lesson input, then build a deterministic source-linked trace.
Source scenarios
Complexity
BestO(log n + k) per query
AverageO(log n + k) per query
WorstO(log n + k) per query
SpaceO(p + n) for p people across n distinct birthday keys
Array state
Follow the active comparisons and writes.
Current operation
Trace stateReady to explore
Source behavior & common mistakes
Add people, retrieve all people with an exact birthday, then flatten a half-open sorted-map range for one calendar year.
- TreeMap orders exact date strings lexicographically; valid zero-padded dates sort chronologically.
- Equal date strings share one list, but distinct Person objects with equal names and dates remain separate entries.
- The exact-date query preserves add order; the year query visits dates in sorted order and then preserves each date list's order.
- The year range is start-inclusive and next-year-exclusive, built exactly as `year + '-01-01'` to `(parseInt(year) + 1) + '-01-01'`.
- The pinned source's valid year 9999 produces a reversed lexical range and TreeMap throws IllegalArgumentException.
Algorithm code
JavaBirthdayMap.javaStep linked
The highlighted line follows the current step.
Ready to begin
Press Play to see what happens.
Detailed execution
Snapshot 1 / 1