+ 1

How to check if an array of integers contain a duplicate number

23rd Apr 2020, 5:32 AM
Kanchan Hidam
Kanchan Hidam - avatar
7 Respostas
+ 2
I would like to see your try first, how about that?
23rd Apr 2020, 6:02 AM
Ipang
+ 1
Hint: * Sort the array. * Save the first element into a variable, assume it as previous value. * Iterate through it beginning from the second element. * During iteration see through it, whether the current element value equals the previous one. * If current value equal to previous value then you know that array contains a duplicate. * If current value not equal to the previous one then assign current value to previous value and continue with next element.
23rd Apr 2020, 5:56 AM
Ipang
+ 1
Tq so much Ipang..😇 But can you please send me the code too🙏
23rd Apr 2020, 6:01 AM
Kanchan Hidam
Kanchan Hidam - avatar
+ 1
Okk
23rd Apr 2020, 6:05 AM
Kanchan Hidam
Kanchan Hidam - avatar
+ 1
Plz check my post
23rd Apr 2020, 6:16 AM
Kanchan Hidam
Kanchan Hidam - avatar
+ 1
Tq so much Hima
25th Apr 2020, 3:41 PM
Kanchan Hidam
Kanchan Hidam - avatar
0
take xor (^) with every element if the result is a non-zero value then your array contains duplicate value/values if it is 0 then it doesn't.
23rd Apr 2020, 6:24 PM
Hima
Hima - avatar