find if two arrays contain the same set of integers without extra space and faster than NlogN

前端 未结 14 769
盖世英雄少女心
盖世英雄少女心 2020-12-02 17:27

I came across this post, which reports the following interview question:

Given two arrays of numbers, find if each of the two arrays have the same s

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 17:52

    A special, not harder case is when one array holds 1,2,..,n. This was discussed many times:

    • How to tell if an array is a permutation in O(n)?
    • Algorithm to determine if array contains n...n+m?
    • mathoverflow

    and despite many tries no deterministic solutions using O(1) space and O(n) time were shown. Either you can cheat the requirements in some way (reuse input space, assume integers are bounded) or use probabilistic test.

    Probably this is an open problem.

提交回复
热议问题