My issue
The code is attached. The code is passing only one test case. I am unable to find the error in logic. It seems fine to me but it’s not working for all the test cases
My code
# cook your dish here
n = int(input())
brac_list = list(map(int, input().split()))
MAX_DEPTH = -1
MAX_DEPTH_START = -1
MAX_LEN = -1
START_MAX = -1
depth = 0
start = 0
max_len = 0
start_m = 0
temp_stack = []
for i in range(n):
if not temp_stack:
if MAX_LEN < max_len:
MAX_LEN = max_len
START_MAX = start_m
start = i
depth = 1
temp_stack.append(1)
start_m = i
max_len = 1
else:
if brac_list[i] == 1:
depth += 1
max_len += 1
temp_stack.append(1)
if MAX_DEPTH < depth:
MAX_DEPTH = depth
MAX_DEPTH_START = i
else:
depth -= 1
max_len += 1
del temp_stack[-1]
print(MAX_DEPTH, MAX_DEPTH_START+1, MAX_LEN, START_MAX+1)
Problem Link: CodeChef: Practical coding for everyone