Longest chain of pairs

后端 未结 5 636
面向向阳花
面向向阳花 2021-02-04 10:16

You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c,d) can follow

5条回答
  •  礼貌的吻别
    2021-02-04 10:50

    We can start with Brian's approach, of sorting all the pairs based on y value. It will ensure the required condition of prev pair's X < next pair's y. Now all we need is longest increasing subsequence of x among the new list of pairs. Which we can get by sorting all x and finding longest common subsequence between sorted x and new list previously created

提交回复
热议问题