Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 1497. Check If Array Pairs Are Divisible by k
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
bool canArrange(vector<int>& arr, int k) {
vector<int> 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;
}();
Loading