Given an array from 0 to n integers containing values 1 through n, write a method that can find any duplicate and return it (note there must be at least one duplicate because of there being more indices than available values). Write a method with "good" running time and space complexity.
Sigiloso
A really neat way to solve this is by doing some math and figuring out 1 + 2 + ... + n = (n+1)*n/2. So what you can do is make a pass through the array and sum up all the values and then subtract the sum from 1 to n and return that value. Or in psuedocode: for i=0 to n: sum += list[i] return sum - n * (n+1) / 2