Before choosing a cache size for a font loader, the team replays a log of font requests through a least recently used cache. A request is a hit if the font is already cached; otherwise it is a miss, the font is loaded into the cache, and if the cache now holds more than capacity fonts, the least recently used font is removed. Every request, hit or miss, counts as a use.
Write countMisses(capacity, requests) that returns the number of misses. The cache starts empty.
Input: capacity = 2, requests = ["inter","roboto","inter","mono","roboto","inter"] Output: 5
inter and roboto miss, inter hits, mono misses and evicts roboto, so roboto misses again and evicts inter, which then misses.
Input: capacity = 3, requests = ["a","b","a","b","a"] Output: 2
Only the first two requests miss.
1 <= capacity <= 10000 <= requests.length <= 10^5Run 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 #694 Count Cache Misses. 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.