DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in competitive programming

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:

  1. Use a dictionary to map digits to their corresponding letters.
  2. Use backtracking to explore all possible combinations of letters for the input digits.

Image description

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:

  1. Use backtracking to explore all possible ways of placing open '(' and close ')' brackets.
  2. The combination is valid by tracking the number of open and close brackets.

Image description

Top comments (0)