You only have free questions left (including this one).

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.

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 method for finding the number that appears twice.

We can do this with additional memory.

Start your free trial!

Log in or sign up with one click to get immediate access to free mock interview questions

Where do I enter my password?

Actually, we don't support password-based login. Never have. Just the OAuth methods above. Why?

  1. It's easy and quick. No "reset password" flow. No password to forget.
  2. It lets us avoid storing passwords that hackers could access and use to try to log into our users' email or bank accounts.
  3. It makes it harder for one person to share a paid Interview Cake account with multiple people.

Start your free trial!

Log in or sign up with one click to get immediate access to free mock interview questions

Where do I enter my password?

Actually, we don't support password-based login. Never have. Just the OAuth methods above. Why?

  1. It's easy and quick. No "reset password" flow. No password to forget.
  2. It lets us avoid storing passwords that hackers could access and use to try to log into our users' email or bank accounts.
  3. It makes it harder for one person to share a paid Interview Cake account with multiple people.

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

. . .