From ac7c975b4b09db160518bf17492b30aae138be23 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:35:45 +0530 Subject: [PATCH] Create 1497. Check If Array Pairs Are Divisible by k --- 1497. Check If Array Pairs Are Divisible by k | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 1497. Check If Array Pairs Are Divisible by k 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; +}();