Category: subsets
-
LeetCode 22: Generate Parentheses
link Valid parentheses have two criteria: Recursive Time: , space: .
-
LeetCode 17: Letter Combinations of a Phone Number
link Recursive Letter combinations of “23” is the cartesian product of corresponding letter sets: {“a”, “b”, “c”} and {“d”, “e”, “f”}. Note, there can be at most four different letters for a digit. Time: , space: . Iterative For each possible letter for a new digit, we can append it to each of the earlier…
-
LeetCode 46: Permutations
link Recursive Time: , space: . Iterative For a new element , for each earlier permutations, we can insert in different positions to get more permutations. Time: , space: .
-
LeetCode 78: Subsets
link Take or skip: Recursion We skip or take each element. Time: , space: . Take or skip: Iterative Say we have subsets with (n-1) elements. For the n-th element, we can take it or we can skip it. Skipping n-th element is same as keeping the subsets with only (n-1) elements or the subsets…