Code RoomLock escalation threshold
MediumPrep Room Coding #306

Lock escalation threshold

CodingConcurrencyMid–Senior~25 min

A database escalates row locks to a table lock to save memory. A transaction acquires row locks over time. acquisitions is a list of row ids (with possible repeats) acquired in order. The lock manager escalates to a single table-level lock the first moment the number of DISTINCT rows held reaches a threshold. Once escalated, all further row acquisitions are absorbed by the table lock (no new row locks tracked). Re-acquiring an already-held row before escalation does not increase the distinct count. Return the 1-based index in 'acquisitions' at which escalation is triggered, or -1 if escalation never happens.

Implement
lock_escalation_point(acquisitions: list[int], threshold: int) → int
Examples
in[[1,2,2,3,4],3]out4
What 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 25 min
InputExpectedGot
[[1,2,2,3,4],3]4not run yetsample