Skip to the code
cf.
+10 XP

#14 Most Clicked Toolbar Button

easy

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.

Example 1

Input: clicks = ["save","undo","save","share","undo","save"]
Output: "save"

save was clicked 3 times, more than any other button.

Example 2

Input: clicks = ["undo","save","save","undo"]
Output: "undo"

Both have 2 clicks; undo was clicked first.

Constraints

  • 1 <= clicks.length <= 10^5
  • Each id is a non-empty string.
Saved in this browser

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).