Check If Array Pairs Are Divisible by k LeetCode solution in C++
1// ask the interviewer2// can we have negative values?34class Solution {5public:6bool canArrange(vector<int> &arr, int k) {7unordered_map<int, int> memo; // remainder : occurence89// we are storing the frequency of curr%k10// i.e. the frequency of the remainder11for (auto curr : arr) {12int remainder = ((curr % k) + k) % k;13memo[remainder]++;14}1516for (int i = 1; i <= k / 2; i++) {17if (memo[i] != memo[k - i]) return false;18}19if (memo[0] % 2 != 0) return false;20return true;21}22};