Step 1 of 4
Hold values and give them back
Start with the boring half: put stores a value under a key, get
returns it, and get on a key you never stored returns -1.
Ignore capacity entirely for now — the cache is allowed to grow without
limit. Eviction is the next step, and building it before the storage works
means debugging two things at once.
put(1, 10) get(1) -> 10
get(7) -> -1size() and keys() are already written for you. Once put and get
maintain the order, those two report it without any work of their own.
Your build
Running is free — Submit is what records the step. Or press ⌘↩
Tests
4 cases, 1 hidden| call | type | expected | result |
|---|---|---|---|
| runOps(2, [["put",1,10],["get",1]]) | stores a value and reads it back | [null,10] | — |
| runOps(2, [["get",7]]) | a key that was never stored reads as -1 | [-1] | — |
| runOps(2, [["put",1,1],["put",2,2],["size"]]) | size counts what is held | [null,null,2] | — |
| withheld | hidden | withheld | — |
Hidden cases run too — their inputs aren't listed here, so aim for a general solution rather than one fitted to the cases above.
Hints
Stuck? Hints open one at a time, each giving a little more away.
3 hints left