An error reporter keeps the most recent user actions ("breadcrumbs") to attach to crash reports. It keeps at most capacity of them: when full, a new breadcrumb overwrites the oldest one. Write a class Breadcrumbs:
new Breadcrumbs(capacity) starts empty.add(action) records an action string.list() returns the stored actions from oldest to newest.dropped() returns how many actions have been overwritten so far.Use a fixed-size array with wrap-around; add must be O(1).
Each example lists the calls in order, then each call's arguments. The first call creates the object with new Breadcrumbs(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["Breadcrumbs","add","add","add","list","add","list","dropped"] [[3],["click"],["scroll"],["type"],[],["submit"],[],[]] Output: [null,null,null,null,["click","scroll","type"],null,["scroll","type","submit"],1]
submit overwrites the oldest action, click, so one action has been dropped.
Input: ["Breadcrumbs","list","dropped"] [[2],[],[]] Output: [null,[],0]
Nothing has been recorded yet.
1 <= capacity <= 1001000 calls.Run 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 #285 Overwriting Breadcrumb Buffer. 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.