I've been working on an interesting problem and figured I should post about it on here. The problem is the following:
You are given two arrays, A and B, such that the elements of each array are 0 or 1. The goal is to figure out if all the 1s in A come before the first 1 in B. You can assume that all 1s are sequential - you cannot have a 0 between 2 ones. (i.e. you would never have [1,0,1]). Some examples:
True: A = [0,1,1,0], B = [0,0,0,1]
True: A = [1,0,0,0], B = [0,1,1,0]
False: A = [0,0,0,1], B = [1,0,0,0]
False: A = [0,1,1,0], B = [0,0,1,0]
You can assume that len(A) = len(B) = N, but N can be very large. Therefore, you cannot simply convert the entire array into a binary number because it will be too large to represent.
I'd like to find the solution in the most efficient way possible, ideally O(1). I've been coding this in Python using Numpy arrays, so you can perform logical operations on the arrays (e.g. A & B, which would tell you if any 1s overlap between A and B). Curious to see any solutions that you can come up with!