A design system's build gives each of n icons an id from 1 to n. A bug wrote n + 1 ids into the manifest ids, so at least one id appears more than once. Exactly one id value is repeated, though it may appear more than twice.
Write findReusedId(ids) that returns the repeated id. Don't change ids, and use only O(1) extra space, so sorting a copy or using a set is out.
Input: ids = [3,1,4,4,2] Output: 4
4 appears twice.
Input: ids = [3,1,3,4,2] Output: 3
3 appears twice.
2 <= ids.length <= 10^5ids.length is n + 1 and 1 <= ids[i] <= n.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 #237 Find the Reused Asset ID. 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.