The problem. Given an array arr with an even number of integers and a number k, can you split all of it into pairs so that the sum of every pair is divisible by k? Return true or false. Every element must be used exactly once.
arr = [9, 7, 5, 3], k = 6 -> true (9 + 3, 7 + 5)
arr = [1, 2, 3, 4, 5, 10, 6, 7, 8, 9], k = 5 -> true (1 + 9, 2 + 8, 3 + 7, 4 + 6, 5 + 10)
arr = [1, 2, 3, 4, 5, 6], k = 10 -> false
arr = [-1, 1, -2, 2, -3, 3, -4, 4], k = 3 -> trueMembers only · free account
The rest of this lesson, with 7 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson