A cinema numbers its tickets 1 to n. After a show, the scanner's log has exactly n entries, but it is wrong in one place: one ticket was scanned twice and one ticket was never scanned. Find both numbers.
Write findRepeatedAndMissing(nums). nums has length n and holds values from 1 to n in any order. Exactly one value appears twice, exactly one value from 1 to n does not appear, and every other value appears once. Return { repeated, missing }.
Rules:
If nums is not an array, or any value is not an integer from 1 to n (where n is the array's length), throw a TypeError. If it has fewer than 2 values, throw a RangeError, because no valid log is that short.
You may assume that a valid array has exactly one repeated and one missing value.
Use O(n) time and O(1) extra space, and do not modify nums. That rules out sorting it in place and building a Set or a count array.
n can be 200,000. Counting each value with a scan of the whole array is quadratic and will not finish in time.