Let's say I have a set of constant-length arrays containing only zeroes and ones. My goal is to find out whether, after any rotation of any of the arrays, the element-wise sums of the arrays will not exceed 1.
For instance, let's say I have the following three arrays: [1, 0, 0, 0], [1, 0, 1, 0]
, and [1, 0, 0, 0]
. I can rotate the second array by one element and the third array by two elements to obtain the arrays [1, 0, 0, 0], [0, 1, 0, 1], [0, 0, 1, 0]
, the element-wise sum of which is [1, 1, 1, 1]
. However, had I not applied the rotations, I would have gotten a sum of [3, 0, 1, 0]
, which does not fit my requirements as one of the elements (the 3) is greater than 1.
Now, my question is, what is a fast way to determine if this is possible for an arbitrary number of arrays? For instance, there is no way to rotate [1, 0, 0, 0], [1, 0, 1, 0], [1, 0, 1, 0]
so that the elements of the sum do not exceed 1.
Current heuristics
Obviously, if the total sum of the arrays, which are, say, length n
, exceeds n
, then this is trivially impossible.
The best idea for an approach I can think of so far is taking two arrays, finding a way to merge them together, and inverting the result. Then, we take this result and the next array, and repeat this process. However, this method does not guarantee to find a solution if one exists.
My question is, short of trying every possible rotation, what would be a good algorithm for this problem?