I have a list of index ranges structured as [(2, 4), (6, 7)].
I also have an array with 10 elements with all False values:
[False, False, False, False, False, False, False, False, False, False]
What I wanna do is modify the values between these ranges and make them True. So the final list would be:
[False, True, True, True, False, True, True, False, False, False]
NB: the indexes of the list doesn't start from zero.
I was thinking of a solution based on two for's, but it has a N^2 complexity:
for i in range(len(list_ranges)):
for j in range(len(my_list)):
if (j >= list_ranges[i][0] or j <= list_ranges[i][1]):
my_list[j] = True
How can I improve the complexity of the algorithm?