How to generate parentheses
[Question]: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example: – n = 2. — [“(())”, “()()”] Approach: We can solve using backtracking / recursion
recursion code examples in swift language.
[Question]: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.Example: – n = 2. — [“(())”, “()()”] Approach: We can solve using backtracking / recursion
[Question]: Given a positive integer number N. The task is to generate all the binary strings of N bits. These binary strings should be in ascending order.Example: – Input: 2Output:0 00 11 01 1
[Question] Write a program to reverse a stack using recursion.Input: elements present in stack from top to bottom 1 2 3 4 Output: 4 3 2 1
[Question]: Given a stack, the task is to sort it using recursion.Input: elements present in stack from top to bottom -3 14 18 -5 30Output: 30 18 14 -3 -5Explanation: The given stack is sorted know 30 > 18 > 14 > -3 > -5
[Question]: Prepare recursion stack for multilevel recursion.
[Question]: Given an integer array that may contain duplicates, find all possible subsets (the power set). No duplicates allowed in answer. Solution in any order allowed. Input: nums = [1,2,3] Output: [1,2,3] [1,2] [1,3] [1] [2,3] [2] [3] [] Approach #2: Using Bitwise OperatorQuestion: Power Set: Print all the possible subsequences of the String To check …
[Question] : Find subset sum in given ArrayExample: Input: N = 6 arr[] = {3, 34, 4, 12, 5, 2} sum = 9 Output: 1 Explanation: Here there exists a subset with sum = 9, 4+3+2 = 9.
[Question]: In a distinct array a target integer target, return a list of all unique combinations of candidateInput: candidates = [2,3,6,7], target = 7 Output: [[2,2,3],[7]]
[Question]: In an array count all possible sequence whose sum is K. example:- [4,8,4] Target Sum = 8 So Output will be 2 because sequences are: [4,4] [8]
[Question] : Print any one sequence whose some is equal to KFor example:- [4,8,4] Target Sum = 8 So Output will be [4,4]