Find duplicate number in array
MediumGiven an
n
size array of integers 1..n
with exactly one duplicate number, write a function that returns the duplicate number.Some examples:
find_duplicate([1, 3, 2, 3])
should return3
find_duplicate([1, 2, 5, 4, 5, 3])
returns5
find_duplicate([1, 2, 1, 3])
returns1
Solution
6 Essential Primitives Coding Interview Problems
Master Primitives by trying the coding challenges below.
- 1.Swap bitsEasy
- 2.Power of twoEasy
- 3.Count bitsMedium
- 4.Reverse bitsMedium
- 5.Find duplicateMedium
- 6.Bitwise additionHard