FastPrepMaximum Bounded One-to-One Pairs
Problems/Maximum Bounded One-to-One Pairs

Maximum Bounded One-to-One Pairs

IBM logoIBM● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IBM new grad online assessment. The report gives the inequality, the rule that each item is used once, the limits on array size, and the limit on distance. It does not give limits on element values or a function signature. Our version is about 98% the same as the reported question.

You are given two nonempty integer arrays arr1 and arr2, and a positive integer d.

Make as many one-to-one pairs (a, b) as you can. Each pair takes an unused element a from arr1 and an unused element b from arr2. A pair is valid only when a <= b <= a + d. Each element can be used in at most one pair.

Return the maximum number of valid pairs. The input arrays do not need to be sorted.

Function

maxValidPairs(arr1: int[], arr2: int[], d: int) → int

Examples

Example 1

arr1 = [8,20,35,45]arr2 = [25,50]d = 10return = 2

Pair 20 with 25 and 45 with 50. Both pairs are valid, because each b is at least its a and at most d above it. arr2 has only two elements, so these two pairs are the most you can make.

Example 2

arr1 = [5,1,3]arr2 = [3,6,2]d = 1return = 3

Use the pairs (1,2), (3,3), and (5,6). In each one, b is at least a and at most d above it. Every element is used, so the answer is three pairs.

Example 3

arr1 = [1,2,3]arr2 = [10,11]d = 2return = 0

Every value in arr2 is more than d above every value in arr1. No pair is valid, so the answer is zero.

Constraints

  • 1 <= arr1.length, arr2.length <= 10^5
  • 0 <= arr1[i], arr2[i] <= 10^9
  • 1 <= d <= 10^5

More IBM Online Assessment questions

  • Missing IntervalsOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026
  • Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
  • Maximum Compatible Time WindowsOA · Seen Oct 2026

Similar questions at other companies

  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
  • Minimum Machines for TasksExpedia · OAExpedia interview questions
  • Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
  • Minimum Days to Watch All MoviesAdobe · OAAdobe interview questions
  • Efficient Janitor TripsRoblox · OARoblox interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
  • Get Maximum PairsAmazon · OA

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int maxValidPairs(int[] arr1, int[] arr2, int d) {
        // write your code here
    }
}
Checking account…