Skip to content

Conversation

@avimishraa
Copy link

This Pull Request adds two hard-level recursion problems from LeetCode, implemented in C++ with clear explanations, optimized recursion logic, and tested outputs.

  1. Regular Expression Matching (LeetCode Updated Readme + TwoSums + Longest Palindromic Substring #10)

Problem Summary:
Implement regular expression matching with support for '.' (matches any single character) and '*' (matches zero or more of the preceding element).

Approach:
Used pure recursion to explore all matching possibilities.

Base condition checks if the pattern is empty.

If the next pattern character is *, recursively try two options:

Skip the * and its preceding character.

Use it if the first characters match.

Otherwise, recursively match the next substring and subpattern.

Complexity:

Time: Exponential (in worst case), can be optimized with DP.

Space: O(N) recursion stack.

  1. N-Queens (LeetCode Happy Number #51)

Problem Summary:
Place n queens on an n×n chessboard such that no two queens attack each other.

Approach:
Implemented a recursive backtracking algorithm that places queens row by row:

At each row, try placing a queen in a valid column (not under attack).

Track columns and diagonals using three boolean arrays.

If all rows are filled successfully, store the board configuration.

Backtrack when conflicts occur.

Complexity:

Time: O(N!) (due to backtracking and branching at each row).

Space: O(N²) for the board and recursion depth.

@welcome
Copy link

welcome bot commented Oct 22, 2025

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉 I'll take a look at it ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant