Find the only unique element in an array of a million elements

前端 未结 4 631
余生分开走
余生分开走 2021-01-04 09:46

I was asked this question in a recent interview.

You are given an array that has a million elements. All the elements are duplicates except one. My task is to find t

4条回答
  •  太阳男子
    2021-01-04 10:40

    Assuming the array is un-ordered, you can't. Every value is mutually exclusive to the next so nothing can be deduced about a value from any of the other values?

    If it's an ordered array of values, then that's another matter and depends entirely on the ordering used.

    I agree the easiest way is to have another container and store the frequency of the values.

提交回复
热议问题