Stack Bash - Master data structures and algorithms

Find duplicate number in array

Medium
Given an n size array of integers 1..n with exactly one duplicate number, write a function that returns the duplicate number.
Some examples:
  1. find_duplicate([1, 3, 2, 3]) should return 3
  2. find_duplicate([1, 2, 5, 4, 5, 3]) returns 5
  3. find_duplicate([1, 2, 1, 3]) returns 1

Solution

6 Essential Primitives Coding Interview Problems

Master Primitives by trying the coding challenges below.
  1. 1.Swap bitsEasy
  2. 2.Power of twoEasy
  3. 3.Count bitsMedium
  4. 4.Reverse bitsMedium
  5. 5.Find duplicateMedium
  6. 6.Bitwise additionHard