Question bank › Monotonic Stack
Dsa Monotonic Stack Hard

Largest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. You need to implement the function `longest_valid_parentheses(s: str) -> int`. ### Input A single line containing a string of parentheses. ### Output An integer representing the length of the longest valid parentheses substring. ### Example Input: )()()) Output: 4

Key concepts

monotonic_stackparenthesesstring

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
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.