Problem 4064 · Hard

Longest Subarray Divisible by K with At Most One Negation II

Keep, for each remainder, the earliest start of subarrays with and without one negation, so each position is handled in one pass over the remainders.

Open the interactive visualisation