But it doesn't have to end here! Sign up for the 7-day coding interview crash course and you'll get a free Interview Cake problem every week.
You're in!
I have an array of n + 1 numbers. Every number in the range 1..n appears once except for one number that appears twice.
Write a function for finding the number that appears twice.
We can do this with additional memory.
Log in or sign up with one click to get immediate access to free mock interview questions
We'll never post on your wall or message your friends.
Actually, we don't support password-based login. Never have. Just the OAuth methods above. Why?
Log in or sign up with one click to get immediate access to free mock interview questions
We'll never post on your wall or message your friends.
Actually, we don't support password-based login. Never have. Just the OAuth methods above. Why?
time. We can sum all the numbers 1..n in time using the fancy formula, but it still takes time to sum all the numbers in our input array.
additional space—the only additional space we use is for numbers to hold the sums with and without the repeated value.
If our array contains huge numbers or is really long, our sum might be so big it causes an integer overflow. What are some ways to protect against this?
Reset editor
Powered by qualified.io