A local dev tool needs a free port number for a new server. The numbers already in use are in ports, which may also hold junk values (zero, negative, repeated, or huge).
Write smallestUnusedPort(ports) that returns the smallest positive whole number not in ports. Do it in O(n) time with O(1) extra memory.
Input: ports = [2,5,1,-4,3] Output: 4
1, 2, and 3 are taken, so 4 is the smallest free number.
Input: ports = [9,8,10] Output: 1
1 is not used.
0 <= ports.length <= 10^5-2^31 <= ports[i] <= 2^31 - 1Run 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 #74 Smallest Unused Port. 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.