Longest Valid Parenthesis [Dynamic programming] | Python Code

preview_player
Показать описание
Question:- Given a string A containing just the characters ’(‘ and ’)’

Find the length of the longest valid (well-formed) parentheses substring.
Returns the length of the longest valid (well-formed) parentheses substring.

Input :-
A = "(()"
Output :-
2

Please help our channel by SUBSCRIBING it.

#longest #valid #parenthesis #netsetos
Рекомендации по теме
Комментарии
Автор

Literally very clear explanation mam. 👏

CSKAASIPRASANTHA
Автор

the explanation is buggy ... at 12:01 A[0-1] -> A[-1] instead of rejecting it will take last value.
according to this, example test case ")(" , value should be 0 but will come 4.

this was corrected in the code

Ayush-mbse
Автор

U can use this as well

val=')()())'
val1=val.count('(')
val2=val.count(')')

if val1 == val2:
print val1*2
else:
print min([val1, val2])*2

saikatdasgupta
Автор

The problem with the explanation is that you didn't say how you came up with the solution.

observr
Автор

please tell the intuition first and then algo. we are here to learn not to memorize.

swatilohiya