pairs
array based on the second element of each pair.curr
to a very small value to represent the end of the current chain.ans
to 0 to keep track of the length of the longest chain.pair
in the sorted pairs
array:
pair
is greater than curr
, increment ans
by 1 and update curr
to the second element of pair
.ans
as the length of the longest chain.