Dsa
Stack
Easy
Longest Valid Parentheses Substring
Given a string containing just the characters '(', ')', find the length of the longest valid (well-formed) parentheses substring.
Input Format:
- The first line contains a string s consisting of '(' and ')'.
Output Format:
- Print the length of the longest valid parentheses substring.
Example:
Input:
(()))
Output:
4
Key concepts
stackparenthesessubstring
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now