You are given an array of n pairs where pairs[i] = [left_i, right_i] and left_i < right_i. A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c, and a chain of pairs can be formed this way. Return the length of the longest chain which can be formed. You do not need to use up all the given pairs, and you can select pairs in any order.
You are given an array of n pairs where pairs[i] = [left_i, right_i] and left_i < right_i. A pair p2 = [c, d] follows a pair p1 = [a, b] if b < c, and a chain of pairs can be formed this way. Return the length of the longest chain which can be formed. You do not need to use up all the given pairs, and you can select pairs in any order.
Example 1:
Input: {"pairs":[[1,2],[2,3],[3,4]]}
Output: 2
Constraints:
n==pairs.length
1≤n≤1000
−1000≤lefti<righti≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"pairs":[[1,2],[2,3],[3,4]]}
3 pair(s) on the number line. A pair can follow another only if it starts strictly after the other ends.