Finding Duplicate Integers
11/19/2019
This post is a continuation of using Vectorization to achieve better performance. In this post I am going to look at the performance aspect of another tipical programming exercises on interviews.
Task usually goes by this:
Given an array with integers from 1 to N. The order of the integers is unknown. One of the randomly chosen number is duplicated by overwriting another number. Create a method that receives the array as an input and returns the replaced number.For example having an input of
[2,5,4,3,1,7,3]
should return 3, as being the duplicate, as number 6 is being overwritten by another 3.
I am not going into the details of edge cases, input validation, error handling, etc. This post purely focuses on the performance aspects of some of the possible solutions. I also assume that N = x * 8.