An analytics script records the id of the element each click lands on, in order, in clicks. A double-submit guard should fire if the same element is clicked twice within k events of each other.
Write hasQuickRepeat(clicks, k) that returns true if there are two indexes i < j with clicks[i] === clicks[j] and j - i <= k, and false otherwise.
Input: clicks = ["buy","menu","buy","help"], k = 2 Output: true
buy is clicked at indexes 0 and 2, which are 2 apart.
Input: clicks = ["buy","menu","help","buy"], k = 2 Output: false
The two buy clicks are 3 apart.
0 <= clicks.length <= 1000000 <= k <= 100000clicks[i] is a non-empty string.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 #127 Repeat Click Within k Events. 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.