The containment rule is where I lost time.
Clarify the data model and semantics first: define how sessions, grants, and salary calculations interact, especially the 'entirely within' condition and exact grant matching. Then outline an efficient data structure (e.g., interval tree or sorted list) to store grants and support fast containment queries, and walk through the implementation of each API with edge cases.
Pro tip: Explicitly discuss how you would handle overlapping grants and whether a session can be doubled more than once; this shows you think about real-world ambiguity and data integrity.
Ask about session granularity, grant overlap rules, and whether get_grant_bonus should sum multiple sessions or return a single value. Confirm that 'exact previously registered grant' means matching start and end timestamps.
Propose storing grants in a balanced BST or interval tree keyed by start time, with end time as value, to enable O(log n) containment checks. For exact grant lookup, use a hash map keyed by (start, end).
Validate that start < end and handle duplicates or overlaps according to clarified rules. Insert into both the interval structure and the hash map.
For each session, check if it is entirely contained within any grant (session.start >= grant.start and session.end <= grant.end). If so, double the pay for that session; otherwise, use normal rate.
Look up the exact grant by (start, end) in the hash map. Iterate over all sessions that fall entirely within that grant and sum the extra earnings (i.e., the additional amount beyond normal pay).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.