Counting unique element in large array

前端 未结 8 718
执念已碎
执念已碎 2021-02-03 15:33

One of my colleagues was asked this question in an interview.

Given a huge array which stores unsigned int. Length of array is 100000000. Find the effective

8条回答
  •  -上瘾入骨i
    2021-02-03 15:53

    Sort it, then scan it from the beginning to determine the counts for each item.

    This approach requires no additional storage, and can be done in O(n log n) time (for the sort).

提交回复
热议问题