1. Letter Combinations of a Phone Number:
This problem asks you to take a string of digits (like "23") and generate all possible letter combinations based on a phone keypad.
Example:
Input: "23"
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
How to solve:
- Use a dictionary to map digits to their corresponding letters.
- Use backtracking to explore all possible combinations of letters for the input digits.
2. Generate Parentheses:
This problem asks you to generate all combinations of n pairs of valid parentheses.
Example:
Input: n = 3
Output: ["((()))", "(()())", "(())()", "()(())", "()()()"]
How to solve:
- Use backtracking to explore all possible ways of placing open '(' and close ')' brackets.
- The combination is valid by tracking the number of open and close brackets.
Top comments (0)