Maximum Length Pair Chain
Updated
Problem statement
You are given an array pairs, where every pair is [start, end] and start < end.
A pair [c, d] may follow [a, b] in a chain only when b < c. You may choose each pair at most once, may leave pairs unused, and may arrange chosen pairs in any order.
Return the maximum possible number of pairs in a valid chain.
Function
maxPairChainLength(pairs: int[][]) → intExamples
Example 1
pairs = [[3,4],[1,2],[2,3]]return = 2One maximum chain is [1,2] -> [3,4]. The pair [2,3] cannot immediately follow [1,2] because the inequality is strict.
Example 2
pairs = [[-10,-5],[-4,0],[1,2]]return = 3All three pairs form a valid chain in their displayed order.
Constraints
1 <= pairs.length <= 1000- Every
pairs[i]has exactly two integers. -10^9 <= pairs[i][0] < pairs[i][1] <= 10^9
More InMobi Onsite Interview questions
- Russian Doll EnvelopesONSITE INTERVIEW · Seen Jul 2026
- Minimum and Maximum with Optimal ComparisonsONSITE INTERVIEW · Seen Dec 2025
- Minimum Edges to Connect All ComponentsONSITE INTERVIEW · Seen Dec 2025
- Shortest Path Visiting All NodesONSITE INTERVIEW · Seen Sep 2025
- Maximum Sum of Non-Adjacent Tree NodesONSITE INTERVIEW · Seen Jan 2022
- Word SquaresONSITE INTERVIEW · Seen Jan 2022
- Top View of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
- Maximum XOR Between Two ArraysONSITE INTERVIEW · Seen May 2021
- Trapping Rain WaterONSITE INTERVIEW · Seen May 2021
- Validate Binary Search TreeONSITE INTERVIEW · Seen May 2021
Similar questions at other companies
- Maximum Length Pair ChainAmazon · ONSITE INTERVIEW
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Unit-Weight Knapsack with Limited QuantitiesGoogle · ONSITE INTERVIEWGoogle interview questions
- Reduce Array Size to At Most HalfMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximize Monsters DefeatedSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Jump Game IIOracle · ONSITE INTERVIEWOracle interview questions