def check_subarray_sum(nums: List[int], k: int) -> bool:
n = len(nums)
mod_seen = {0: -1} # for prefixes that exactly sum%k to 0
prefix_sum = 0
for i in range(n):
prefix_sum = prefix_sum + nums[i]
prefix_mod = prefix_sum % k
if prefix_mod in mod_seen:
if i - mod_seen[prefix_mod] > 1:
return True
else:
mod_seen[prefix_mod] = i
prefix_sum = prefix_mod
return False