A form submits to the server and logs a fingerprint of each submission in ids. A double submit shows up as the same fingerprint twice, close together.
Write repeatWithinK(ids, k) that returns true if there are two different indexes i and j with ids[i] === ids[j] and Math.abs(i - j) <= k.
Input: ids = ["a","b","c","a"], k = 3 Output: true
The two as are 3 apart, which is within k = 3.
Input: ids = ["a","b","c","a"], k = 2 Output: false
The only repeat is 3 apart, more than 2.
0 <= ids.length <= 10^50 <= k <= 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 #23 Repeat Within K Requests. 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.