Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.11 KB

_1497. Check If Array Pairs Are Divisible by k.md

File metadata and controls

42 lines (29 loc) · 1.11 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : October 01, 2024

Last updated : October 01, 2024


Related Topics : Array, Hash Table, Counting

Acceptance Rate : 46.28 %


Solutions

Python

class Solution:
    def canArrange(self, arr: List[int], k: int) -> bool:
        if k == 1 :
            return True

        # Count the remainders after mods
        remainders = [0] * k
        for num in arr :
            remainders[num % k] += 1

        return all(remainders[x] == remainders[k - x] for x in range(1, k // 2)) and \
                ((k % 2 == 1 and remainders[k // 2] == remainders[ceil(k / 2)]) or 
                 (k % 2 == 0 and remainders[k // 2] % 2 == 0))