Skip to content

Commit

Permalink
Add some code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeAbinash committed Oct 1, 2024
1 parent e007d98 commit 792d625
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public boolean canArrange(int[] arr, int k) {
int freq[] = new int[k];
for (int n : arr)
freq[(n % k + k) % k]++;

if (freq[0] % 2 != 0) // k - 0 = k and it does not exist in the array
return false;

for (int i = 1; i <= k / 2; i++)
if (freq[i] != freq[k - i])
return false;

return true;
}
}

0 comments on commit 792d625

Please sign in to comment.