diff --git a/1497. Check If Array Pairs Are Divisible by k b/1497. Check If Array Pairs Are Divisible by k new file mode 100644 index 0000000..1489536 --- /dev/null +++ b/1497. Check If Array Pairs Are Divisible by k @@ -0,0 +1,21 @@ +class Solution { +public: + bool canArrange(vector& arr, int k) { + vector freq(k,0); + for(auto& it: arr){ + int rem = it % k; + if(rem < 0) rem += k; + freq[rem]++; + } + + if(freq[0] % 2) return false; + + for(int i=1; i<=k/2; i++){ + if(freq[i] != freq[k-i]) return false; + } + return true; + } +}; +auto speedup = []() +{ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; +}();