Skip to content

Create 1497. Check If Array Pairs Are Divisible by k #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2024
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