This was an interview question.
I was given an array of n+1
integers from the range [1,n]
. The property of the array is that it has k (k&
It depends what tools are you(your app) can use. Currently a lot of frameworks/libraries exists. For exmaple in case of C++ standart you can use std::map<> ,as maraca mentioned.
Or if you have time you can made your own implementation of binary tree, but you need to keep in mind that insert of elements differs in comarison with usual array. In this case you can optimise search of duplicates as it possible in your particular case.
binary tree expl. ref: https://www.wikiwand.com/en/Binary_tree