Dsa
Stack
Medium
Minimum Parentheses Additions
Given a string of parentheses, calculate the minimum number of parentheses additions required to make the string valid. The string can contain only '(' and ')'. Your task is to implement the function `min_additions(s: str) -> int`.
Input:
- A single string containing only the characters '(' and ')'.
Output:
- An integer representing the number of additions needed.
Example:
Input:
())(
Output:
3
Key concepts
stackstringcounting
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