An editor logs the id of every toolbar button a user clicks, in order, in clicks.
Write mostClicked(clicks) that returns the id clicked most often. If several ids tie for the most clicks, return the one whose first click came earliest in clicks.
Input: clicks = ["save","undo","save","share","undo","save"] Output: "save"
save was clicked 3 times, more than any other button.
Input: clicks = ["undo","save","save","undo"] Output: "undo"
Both have 2 clicks; undo was clicked first.
1 <= clicks.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 #14 Most Clicked Toolbar Button. 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.