28. Find the Closest Pair from Two Arrays
β GFG solution to Find the Closest Pair from Two Arrays: find pair with sum closest to target using efficient two-pointer technique. π
π§© Problem Description
π Examples
Example 1
Input: arr1[] = [1, 4, 5, 7], arr2[] = [10, 20, 30, 40], x = 32
Output: [1, 30]
Explanation: The closest pair whose sum is closest to 32 is [1, 30] = 31.Example 2
Input: arr1[] = [1, 4, 5, 7], arr2[] = [10, 20, 30, 40], x = 50
Output: [7, 40]
Explanation: The closest pair whose sum is closest to 50 is [7, 40] = 47.Example 3
π Constraints
β
My Approach
Two-Pointer Strategy
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated