Skip to content

Commit ee11b16

Browse files
committed
Correct complexity estimation
1 parent 29f5618 commit ee11b16

File tree

1 file changed

+6
-1
lines changed
  • lib/src/medium/22.generate_parentheses

1 file changed

+6
-1
lines changed

lib/src/medium/22.generate_parentheses/main.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
/// The time and space complexity of this code is `O(4^n / √n)`
1+
/// The average time and space complexity of this code is `O(4^n / √n)`.
2+
/// This is because we have `2^n` left bracket and `2^(n-1)` right bracket
3+
/// combinations. Here we get `2^n x 2^(n-1) = 4^n`.
4+
/// There are also `√n` invalid combinations with right bracket
5+
/// on the left position and left bracket on the right position.
6+
/// That's why we have to divide `4^n` by `√n`.
27
38
class Solution {
49
List<String> generateParenthesis(int n) {

0 commit comments

Comments
 (0)