I'm looking forward to a less time complexity based approach of finding index containing duplicate elements in an array using C language. E.g. data array= {1,2,3,4,5,3} Result: 2,5 Considering at Max only 2 elements can repeat in the array not more than that.
I have thought about brute force method which has a high complexity of O(n2) and also space complexity equal to size of array itself (create another array say x with all 0 value, size equal to data array). Firstly I can compare each element with the other in data array and if there is duplicate, update the indices of the duplicate elements with value 1 in array x (and in next term update common sharing position with value 2 and so on and in X). Finally the elements in array X with same value will tell what indices have sharing. Can someone guide me a simpler approach that can help to know indices have duplicate and a method to store it as well.
Thanks.