Given a collection of distinct integers, return all possible permutations.

Example: Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] The solution for this problem can be solved in 2 ways: 1. Using recursion 2. Using next permutation. 3. Using Heap’s algorithm < https://en.wikipedia.org/wiki/Heap%27s_algorithm> First we shall look at the code, later I shall explain about the working of all three the solutions […]

Merge k sorted linked lists and return it as one sorted list in C++

Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4->5->6 This problem can be solved by below given ways: 1. Using Map 2. Using merge Sort or Divide and Conquer 3. Using Recursive 4. Using Priority Queue Here we shall discuss about 2 solutions 1. Using merge sort or Divide and Conquer 2. Using Recursive Before […]

Swap Nodes in Pairs solution in C

Given a linked list, swap every two adjacent nodes and return its head. Example: Given 1->2->3->4, you should return the list as 2->1->4->3. Note: • Your algorithm should use only constant extra space. • You may not modify the values in the list’s nodes, only nodes itself may be changed. We can solve the above […]