Question: Given an array of N integer such that only one integer is repeated. Find the repeated integer in O(n) time and constant space. There is no range for the value of integers or the value of N

For example given an array of 6 integers as 23 45 67 87 23 47. The answer is 23
(I hope this covers ambiguous and vague part)

I searched on the net but was unable to find any such question in which range of integers was not fixed.
Also [here](http://aperiodic.net/phil/archives/Geekery/find-duplicate-elements.html) is an example that answers a similar question to mine but here he created a hash table with the highest integer value in C++.But the cpp does not allow such to create an array with 2^64 element(on a 64-bit computer).

I am sorry I didn't mention it before the array is immutable

Answer: 
Jun Tarui has [shown](http://www.jtlab.ice.uec.ac.jp/~tarui/tarui-tamc07.pdf) that any duplicate finder using O(log n) space requires at least Ω(log n / log log n) passes, which exceeds linear time. I.e. your question is provably unsolvable even if you allow logarithmic space.

There is an interesting [algorithm](http://research.microsoft.com/pubs/77590/GopalanP.pdf) by Gopalan and Radhakrishnan that finds duplicates in one pass over the input and O((log n)^3) space, which sounds like your best bet a priori.

[Radix sort](https://en.wikipedia.org/wiki/Radix_sort) has time complexity O(kn) where k > log\_2 n often gets viewed as a constant, albeit a large one. You cannot implement a radix sort in constant space obviously, but you could perhaps reuse your input data's space.

There are numerical tricks if you assume features about the numbers themselves. If almost all numbers between 1 and n are present, then simply add them up and subtract n(n+1)/2. If all the numbers are primes, you could cheat by ignoring the running time of division.

As an aside, there is a well-known lower bound of Ω(log\_2(n!)) on comparison sorting, which suggests that google might help you find lower bounds on simple problems like finding duplicates as well.
We can do in linear time o(n) here as well

```
public class DuplicateInOnePass {

    public static  void duplicate()

   {
        int [] ar={6,7,8,8,7,9,9,10};
        Arrays.sort(ar);
        for (int i =0 ; i <ar.length-1; i++)
        {

            if (ar[i]==ar[i+1])
                System.out.println("Uniqie Elements are" +ar[i]);

        }  

    }

    public static void main(String[] args) {
        duplicate();
    }
}

```