#1497
Check If Array Pairs Are Divisible by k
specialist · 925 · lc medium +32 · verified · 46.2% accepted · 2,618 likes · top 30%
Description
Given an even-length integer array arr and an integer k, determine whether the array can be partitioned into n / 2 pairs where each pair's sum is divisible by k. Return true if such a pairing exists, otherwise false.
Example 1:
Input: arr = [1,2,3,4,5,10,6,7,8,9], k = 5
Output: true
Explanation: Pairs are (1,9),(2,8),(3,7),(4,6) and (5,10).
Example 2:
Input: arr = [1,2,3,4,5,6], k = 7
Output: true
Explanation: Pairs are (1,6),(2,5) and(3,4).
Example 3:
Input: arr = [1,2,3,4,5,6], k = 10
Output: false
Explanation: You can try all possible pairs to see that there is no way to divide arr into 3 pairs each with sum divisible by 10.
Code
1
2
3