Efficient algorithm to determine if two sets of numbers are disjoint

后端 未结 4 1893
生来不讨喜
生来不讨喜 2020-12-21 11:07

Practicing for software developer interviews and got stuck on an algorithm question.

Given two sets of unsorted integers with array of length m and other of          


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 11:35

    Here's a link to a post that I think answers your question.

    3) Sort smaller O((m + n)logm)

    1. Say, m < n, sort A
    2. Binary search for each element of B into A

    Disadvantage: Modifies the input

提交回复
热议问题