Skip to main content
added 242 characters in body
Source Link
kglr
  • 403.4k
  • 18
  • 501
  • 959

LongestOrderedSequence

If your input list is already sorted by the first column:

LongestOrderedSequence[l, #[[2]] >= #2[[2]] &] 

{{1, 4}, {2, 4}, {5, 3}, {6, 2}}

In general, for arbitrary list of pairs not necessarily sorted by the first column:

LongestOrderedSequence[l, And[#[[1]] <= #2[[1]], #[[2]] >= #2[[2]]] &] 

{{1, 4}, {2, 4}, {5, 3}, {6, 2}}

LongestOrderedSequence

LongestOrderedSequence[l, And[#[[1]] <= #2[[1]], #[[2]] >= #2[[2]]] &] 

{{1, 4}, {2, 4}, {5, 3}, {6, 2}}

LongestOrderedSequence

If your input list is already sorted by the first column:

LongestOrderedSequence[l, #[[2]] >= #2[[2]] &] 

{{1, 4}, {2, 4}, {5, 3}, {6, 2}}

In general, for arbitrary list of pairs not necessarily sorted by the first column:

LongestOrderedSequence[l, And[#[[1]] <= #2[[1]], #[[2]] >= #2[[2]]] &] 

{{1, 4}, {2, 4}, {5, 3}, {6, 2}}

Source Link
kglr
  • 403.4k
  • 18
  • 501
  • 959

LongestOrderedSequence

LongestOrderedSequence[l, And[#[[1]] <= #2[[1]], #[[2]] >= #2[[2]]] &] 

{{1, 4}, {2, 4}, {5, 3}, {6, 2}}