← run

he-006

1.000
1/1 tests· algorithms

Proposed solution

Looking at this problem, I need to:

1. Parse a string containing multiple groups of nested parentheses separated by spaces
2. For each group, calculate the maximum nesting depth
3. Return a list of these maximum depths

Let me trace through the example:
- `'(()()) ((())) () ((())()())'` 
- Group 1: `(()())` - max depth is 2
- Group 2: `((()))` - max depth is 3  
- Group 3: `()` - max depth is 1
- Group 4: `((())()())` - max depth is 3

So the result should be `[2, 3, 1, 3]`.

My approach:
1. Split the input string by spaces to get individual groups
2. For each group, track the current nesting level and maximum nesting level
3. For each character in a group: 
   - If it's '(', increment current level and update max if needed
   - If it's ')', decrement current level
4. Return list of maximum depths for all groups

```python
from typing import List


def parse_nested_parens(paren_string: str) -> List[int]:
    """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
    For each of the group, output the deepest level of nesting of parentheses.
    E.g. (()()) has maximum two levels of nesting while ((())) has three.

    >>> parse_nested_parens('(()()) ((())) () ((())()())')
    [2, 3, 1, 3]
    """
    groups = paren_string.split()
    result = []
    
    for group in groups:
        max_depth = 0
        current_depth = 0
        
        for char in group:
            if char == '(':
                current_depth += 1
                max_depth = max(max_depth, current_depth)
            elif char == ')':
                current_depth -= 1
                
        result.append(max_depth)
    
    return result
```

Test output (stdout)

.                                                                        [100%]
1 passed in 0.01s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.