Determine whether any permutation of a given array exists such that the sum of all subarrays of length K are equal
Use the collections.Counter instead of keeping a count yourself.

When you have counted all the elements from the list, check if any of their counts is not a factor of \$ N \$ and return False.

Therefore:

from collections import Counter

def check(nums, n, k):
    if n == k:
        return True
    counts = Counter(nums)
    if len(counts) &gt; k:
        return False
    return all((n % x == 0 for x in counts.values()))