Getting WA for some test cases in ZCO12001

Here is the code, I’ve written.

def max_depth(brac):
	m, mi = 0, 0
	i, l = 0, 0
	for i in range(len(brac)):
		if brac[i] == '1': l += 1
		else: 
			if l > m: 
				m = l
				mi = i
			l = 0
	return f'{m} {mi}'
	
def max_lenth(brac):
	c, m, ml, p, pl = 0, 0, 0, 0, 0
	for i, x in enumerate(brac): 
		if x == '1': 
			c += 1
			ml += 1
		else: 
			c -= 1
			ml += 1
		if c == 0: 
			if ml > m: 
				m = ml
				p = i-ml
			ml = 0				
	return f'{m} {p+2}'
	
_, brac = input(), input().split()
print(f'{max_depth(brac)} {max_lenth(brac)}')

Someone can please point out what Am I doing wrong?

Consider the test input:

10
1 1 1 2 1 1 2 2 2 2

My code is returning 3 3 10 1 as output. and I assume, It is the right output. Because the maximum nesting depth is 3 and the first position that achieves the nesting depth is 3. And 10 is the maximum sequence and it starts at position 1.

Largest Nesting Depth: 4, occurring for the first time in below range:
((()(())))
└────┘
Largest dist between matched brackets: 10, occurring for the first time in below range:
((()(())))
└────────┘

Thank you for you help :+1: :+1:. I got where I was wrong.

1 Like