Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: [“((()))”,”(()())”,”(())()”,”()(())”,”()()()”]Example 2: Input: n = 1 Output: [“()”] Solution: This problem can be solved using the concept of backtracking, Let’s see how to approach it. We have to write a function generate([], left, right, […]

September 24, 2024 | 23 DSA Patterns | No comments

What is Factorial of a number? The product of all positive descending integers is the factorial of n. n! represents the factorial of n. As an example: 4! is pronounced “4 factorial” in this context, and it is also known as “4 bang” or “4 shriek.” The factorial is typically used in Combinations and Permutations […]

November 23, 2022 | C++ | No comments

The largest number that divides two or more numbers is the Greatest Common Divisor (GCD) for those numbers. For example: Let’s say we have two numbers 45 and 27. So, the GCD of 95 and 30 is 5. Program Code: Output: gcd() is a recursive function in the preceding program. It contains two parameters, a […]

November 20, 2022 | C++ | No comments

The Fibonacci Series generates the next number by adding two preceding numbers. The Fibonacci sequence begins with two numbers, F0 and F1. F0 and F1 can have initial values of 0 and 1, respectively. For instance, Program Code: Output: Note: also read about Convert Decimal to Binary Follow Me Please follow me to read my latest […]

November 18, 2022 | C++ | No comments