# Find duplicate in an array of integers given that the integers are in random order and # not necessarily each integer i is 0 <= i <= N where N = length of array def duplicate(arr): tortoise = arr[0] hare = arr[0] while True: tortoise = arr[tortoise] hare = arr[arr[hare]] if tortoise == hare: break ptr1 = nums[0] ptr2 = tortoise while ptr1 != ptr2: ptr1 = nums[ptr1] ptr2 = nums[ptr2] return ptr1