Maximum Length Pair Chain Problem Statement

You are provided with 'N' pairs of integers such that in any given pair (a, b), the first number is always smaller than the second number, i.e., a < b. A pair chain is defined as a sequential arrangement of pairs where a pair (c, d) can follow another pair (a, b) if b < c.

Objective:

Determine the length of the longest pair chain that can be formed using the given pairs.

Example:

Input:
Pairs =  [3,4], [1,2], [2,3]
Output:
2
Explanation:

The longest pair chain is [1,2] -> [3,4].

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 104
  • -109 <= a, b <= 109
Note:

- Each pair can be used only once.

- Not all pairs need to be used.

- Pairs may be selected in any order.

Input Format:

The first line contains an integer ‘T’ representing the number of test cases.
For each test case, the first line contains a single positive integer ‘N’ which is the number of pairs.
Each of the next ‘N’ lines contains two integers 'a' and 'b' denoting the pair elements.

Output Format:

For each test case, return a positive integer indicating the maximum possible length of the pair chain. Print each result on a new line.
Additional Note:
Implement the function only; do not handle input/output as it is managed elsewhere.
Be the first one to answer
Add answer anonymously...
Siemens Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter