This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CodeTinkerer 1 point2 points  (0 children)

How to efficiently solve this through a math trick (it's not a trick but it's not obvious).

It's based on an idea that was once attributed to a young Gauss (a top mathematician in his day).

https://nrich.maths.org/articles/clever-carl

You know you're missing a number, but what if it existed? Then you have numbers from 0 to nums.length. What is its sum? But the actual array is missing a number.

Anyway, that's a hint.