---
# System prepended metadata

title: 20220225 Min Mock Leo

---

# 20220225 Min Mock Leo



```python=
// n = 2
// "()"
// n  = 4
// "(())", "()()"


info
----

input integer -> n (only even number)
output List[str] -> 



testcase:
    
n = 0 -> []

n = 2 -> ["()"]

n = 4 -> ["(())", "()()"]

for example:
    
n = 2

count = 0
"()"
  ^

time complexity: O(2^n) * O(n)
space complexity: O(2^n) * O(n)

n = 2

round1

paths: ["((", "()"]

case: "()"
       ^
count = 0


    def solve(n: int) -> list:
        # validate the experession
        def validate(s: str) -> bool:
            count = 0
            for char in s:
                if char == "(":
                    count += 1
                else:
                    count -= 1

                if count < 0:
                    return False

            return True if count == 0 else False

        def build(n: int, count: int, path: list) -> str:
            if n == 0:
                paths.append("".join(path))
                return
            
            build(n - 1, count + 1, path + ["("])
            
            if count > 0:
                build(n - 1, count - 1, path + [")"])

        paths = []
        build(n, 0, [])
        return [path for path in paths if validate(path)]
```
