File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
def generate_parentheses_iterative (length : int ) -> list :
2
2
"""
3
3
Generate all valid combinations of parentheses (Iterative Approach).
4
-
4
+
5
5
The algorithm works as follows:
6
6
1. Initialize an empty list to store the combinations.
7
7
2. Initialize a stack to keep track of partial combinations.
@@ -12,16 +12,16 @@ def generate_parentheses_iterative(length: int) -> list:
12
12
c. If open count is < length, push new combination with added '(' onto the stack.
13
13
d. If close count < open count, push new combination with added ')' on stack.
14
14
5. Return the result containing all valid combinations.
15
-
15
+
16
16
Args:
17
17
length: The desired length of the parentheses combinations
18
-
18
+
19
19
Returns:
20
20
A list of strings representing valid combinations of parentheses
21
-
21
+
22
22
Time Complexity:
23
23
O(2^(2n))
24
-
24
+
25
25
Space Complexity:
26
26
O(2^(2n))
27
27
You can’t perform that action at this time.
0 commit comments