Suppose I have a list say x=[1,0,0,1,0,1,1,1,0,1,1,0] . The longest subarray, which has continuous 1, has a length of 3. I have an o (n) approach, but can this be done in o(logn) using a segment tree and how? I deal with problems based on the segment tree, and I'm curious how to approach this, I want to reduce complexity.
a=[1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,1,1,0] size=len(a) counter=0 lis=[] for _ in range(size): if a[_]==1: counter+=1 else: lis.append(counter) counter=0 print(max(lis))
Om sharma
source share