Example: Input: Output: , , ] In my previous post, we have discussed three solutions where the numbers are unique. Recommend to read that post before proceeding to this. This problem can also be solved in 4 different ways. Namely: Backtracking Using set STL …
Example 1: Input: num1 = "2", num2 = "3" Output: "6" Example 2: Input: num1 = "123", num2 = "456" Output: "56088" First, we shall look how we do normal multiplication: If we try to multiply integer num_1 = “1 2 3” with num_2 …
Example: Input: Output: , , , , , ] The solution to this problem can be solved in 2 ways: Using recursion Using the next permutation. Using Heap’s algorithm First, we shall look at the code, later I shall …
Each element may only be used once in the combination Example 1: Input: candidates = , key = 8, A solution set is: , , , ] Before going through this solution, I suggest you please go through “Combination Sum 1”. In that post I have explained …
Problem explanation: Initial Sorted array: After rotation it becomes . Target = 0 Index = 4 This problem can be solved in 2 ways: Linear Search Modified Binary search Linear search: In this solution, we search the element one by one and return the index. …
Examples: Input -> output 1,2,3 → 1,3,2 3,2,1 → 1,2,3 1,1,5 → 1,5,1 Problem explanation: Given a number, find the next highest number, using the same digits given in the array. For example: 1234 -> 1243 Here 1235 is invalid because digit “5” is not in the input array. Hence the next …
The two separate list, merge them to create a new list. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 The solution as expected is very simple. In this tutorial we shall look at 2 different solutions: Iterative Method Recursion Method For both the solution the concept …
Problem Statement: Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. Return the quotient after dividing dividend by divisor. Example 1: Input: dividend = 10, divisor = 3 Output: 3 Both dividend and divisor will be 32-bit signed integers. The divisor will …
Problem description: Given a linked list, remove the n-th node from the end of the list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. We shall solve this problem …