27/39
Part 5 of 7 · Doubly linked listsLearn
Each session is dropped once, so live is amortized O(1)
Every call is O(1) except live, which drops each expired session once. A session is started once and dropped once, so n calls cost O(n) in total: amortized O(1) each, meaning O(1) on average over a run of calls.
Expiry order holds only while every session gets one ttl and time never goes back
The whole design leans on two facts: every session gets the same ttl, and now never goes back from one call to the next. Break the second and the order breaks with it.
ttl is 10. start("a", 5), then start("b", 0), with time going back. live(12) drops sessions from the front while they have expired. What does it return?
Pick an answer above to see the rest