Maximum Factor-Two Pair Count
Updated
Problem statement
Return the greatest number of pairs you can make by taking one element from a1 and one from a2 for each pair. A pair is valid when 2 * a1[i] <= a2[j].
Use each array occurrence at most once. Equal values at different indices are separate occurrences. Array order does not restrict which elements may pair, and either array may be empty.
This pair-count exercise uses the factor-two rule.
Function
maxFactorTwoPairs(a1: int[], a2: int[]) → intExamples
Example 1
a1 = [3,1,2]a2 = [3,4,2,1]return = 2Pair the occurrence with value 1 to value 2, and value 2 to value 4. The remaining value 3 would need at least 6, so a third pair is impossible.
Example 2
a1 = [40]a2 = [10,20,30,40]return = 0The only left value needs a right value of at least 80; none is available.
Constraints
- For this exercise, assume
0 <= a1.length, a2.length <= 500. - Each value is a signed 32-bit integer:
-2147483648 <= value <= 2147483647. - Evaluate
2 * a1[i]mathematically, without signed 32-bit overflow.
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Maximize Center A Package BenefitAmazon · OA
- EV Charging Cost OptimizationTata Consultancy Services · OATata Consultancy Services interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
Interview reports that mention this question
JP Morgan Chase interview experiences
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)