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
Data structure & algorithm using 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]: Given an integer array nums and an integer k, remove all occurrences of k in nums in-place. The order of the elements may be changed. Then return the count after removal Approach: We can declare a variable which holds index initial it’s 0 now move elements which are not matched with k
[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]: Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = “abcabxy” Output: 5 Explanation: The answer is “abcxy”, with the length of 5
[Question]: Given a linked list where every node represents a linked list and contains two pointers of its type: Condition: All linked lists are sorted and the resultant linked list should also be sorted
[Question]: Given the head of a linked list, rotate the list to the right by k places.Example: – Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] #Approach Step: 1 Create tail node which moves till endsStep: 2 Create curr the tail node is the (len-k)-th node (1st node is head)Step: 3 Reorder linked list
[Question]: Given the head of a linked list, reverse the nodes of the list k at a time, and return the updated list. k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is. …
How to Reverse a Linked List in groups of given size Read More »
[Question]: Create a deep copy of the linked list. which consist of exactly n fresh new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and random pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent …
How to create deep copy of linked list who has random pointer Read More »