Problem Explanation: 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. We can solve the above problem with 2 solutions. Iterative Recursive According to the problem we need to solve it using constant …
For example, given n = 3, a solution set is: This problem can be solved in many different ways. Some of them include “DFS”, “BFS”, “backtracking”, “Dynamic Programming”, “Recursion”. In this tutorial, we shall consider the “Recursion” solution. If you need help in solving in another method, please …
Note: The solution set must not contain duplicate quadruplets. Example: Given array nums = , and target = 0. A solution set is: , , ] Below are the steps to solve this problem. Step 1: Sort the array in ascending order. Step 2: Now we …
Input = , Output: , ] This problem can be solved in 2 ways: Time complexity O (n ^ 3). Time complexity O(n^2). We shall look into both of the solutions now: Solution 1: Iterative method: The solution here is simple, we take 3 pointers …
Given array has non repeating array and is sorted. Example 1: Input: Array = , key = 7, Output: , ] Example 2: Input: array = , key = 8, A solution set is: , , ] Here as there is no time …
Problem description: You are given non negative integers “i” represents x axis, and “a” represents y axis. “n” vertical lines are drawn, find two lines together x axis that forms a container. Find the container such that the container will hold the most water. I understand …
Given an input string (s) and a pattern (p), implement regular expression matching with support for ‘.’ and ‘*’. Note: '.' Matches any single character. '*' Matches zero or more of the preceding element. Example 1: Input: Pattern: a.b Valid Strings: acb - any character can be present …
A palindromic string will give the same string when reading reverse. Example: “aba” reverse is “aba” hence is a palindromic string. Input: ashdkabajjseiw Output: aba There are 3 approaches, in this tutorial, we shall discuss 2 methods Brute force approach. Time Complexity O(n ^ 3) Dynamic …