The longest sublist algorithm

前端 未结 2 1989
北恋
北恋 2021-01-07 14:44

I\'m struggling with quite interesting assignment and looking for advice. The case is to find the longest sublist from the given list of pairs. First elements from these pai

2条回答
  •  攒了一身酷
    2021-01-07 15:39

    Okay, a hint first.

    For every pair (x, y) for a given x, you're only interested in the one with the greatest y.

    For every pair (x, y) for a given y, you're only interested in the one with the smallest x.

    Try building maps of respective least/greater values for the x's and y's and see where you get from there (you will need two copies of the pair list, one sorted lexicographically x -> y and one sorted lexicographically y -> x).

提交回复
热议问题