Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

s =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Greedy range of possible open-paren counts.

Approach

Maintain:

  • lo = minimum possible number of opens
  • hi = maximum possible number of opens Process chars:
  • '(' => lo++, hi++
  • ')' => lo--, hi--
  • '*' => lo-- (treat as ')'), hi++ (treat as '(') Clamp lo to 0. If hi < 0, impossible. Valid if lo==0 at end.
Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Greedy range of possible open-paren counts.

Approach

Maintain:

  • lo = minimum possible number of opens
  • hi = maximum possible number of opens Process chars:
  • '(' => lo++, hi++
  • ')' => lo--, hi--
  • '*' => lo-- (treat as ')'), hi++ (treat as '(') Clamp lo to 0. If hi < 0, impossible. Valid if lo==0 at end.
Code
Loading...
Complexity
Time: O(n)
Space: O(1)