A collaborative editor records every change to a document setting, so it can show what the settings were at any moment. Build a class SettingsHistory:
set(key, value, time) records that setting key became value at time. For each key, time only grows from one set call to the next.get(key, time) returns the value of key at time: the value from the latest set for that key whose time is at most time. If there is none, return the empty string "".set returns nothing. Make get fast even when a key has many changes.
Each example lists the calls in order, then each call's arguments. The first call creates the object with new SettingsHistory(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["SettingsHistory","set","get","get","set","get","get"] [[],["theme","light",1],["theme",1],["theme",0],["theme","dark",4],["theme",3],["theme",5]] Output: [null,null,"light","",null,"light","dark"]
At time 3 the latest change was light (time 1). At time 5 it is dark (time 4). Nothing was set before time 1.
Input: ["SettingsHistory","get","set","get"] [[],["font",10],["font","serif",10],["zoom",10]] Output: [null,"",null,""]
Asking before any change gives "", and zoom was never set.
100000 calls in total.1 <= time <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #160 Settings History Store. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.