recursion code examples in swift language.

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

Return all possible subset from an array

[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 …

Return all possible subset from an array Read More »