I have several arrays of variable lengths filled with tuples that represent good and bad blocks of data.
input = [
[(True, 0, 400), (False, 400, 500), (True, 500, 1000)],
[(True, 0, 200), (False, 200, 400), (True, 400, 1000)],
[(False, 0, 100), (True, 100, 1000])]]
What I want to do is create a new list of tuples that represent blocks of data that are good across all of my arrays. The above would end up as follows.
output = [(False, 0, 100), (True, 100, 200), (False, 200, 500),
(True, 500, 1000)]
The tuples in each original array are guaranteed to be alternating True and False. Each array will also have the same start and end (in the case above would be 0 and 1000).
test = fn(input)
assert test == output
My goal is to make this work in O(n) time but I haven't been able to figure it out.