Skip to main content
All Questions

Find the maximum number of valid pairs between two arrays.

Unlock detailed company stats for this questionUpgrade

Given two arrays arr1 and arr2 and an integer d, form the maximum number of pairs (arr1[i], arr2[j]) satisfying arr1[i] <= arr2[j] <= arr1[i] + d. Each element can be used in at most one pair. Example: arr1 = [8, 20, 35, 45], arr2 = [25, 50], d = 10 gives 2 pairs: (20, 25) and (45, 50). Constraints: 1 <= arr1.size(), arr2.size() <= 10^5, 1 <= d <= 10^5.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.