OK, Let me have a take on this.
- Find the largest element(say
max
) in the array. (O(N) operation) - Create a
boolean
array(saytemp
) of sizemax
. - Traverse through the original array and use the current_value as
index
fortemp
array and check if it istrue
i.e.if (temp[current_value] == true)
- If it is
true
you have found the repeating element else settemp[current_value] = true
Obviously this algorithm is not space efficient as we don't know what would be the size of the temp
array and most of the spaces in the temp array would never be visited but it's time complexity is O(N)