Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1774 of 2650
355 Views
Suppose we have one binary search tree, now consider two elements of this BST is swapped, so we have to recover this binary search tree.So if the given tree is like below (first one), the recovered tree will be (second one) −To solve this, we will follow these steps −Define some prev, first, second reference for nodesDefine one method called findProblem(), this will take nodeif node is null, then returncall findProblem(left of node)if prev is not null and value of prev > value of node, thenif first is null, then first = prevsecond := nodeprev := nodecall findProblem(right of node)From ... Read More
502 Views
Suppose we have three strings s1, s2 and s3. Then check whether s3 is formed by interleaving s1 and s2 or not. So if the strings are “aabcc”, s2 = “dbbca”, and s3 is “aadbbcbcac”, then the result will be true.To solve this, we will follow these steps −Define one method called solve(), this will take s1, s2, s3 and one 3d array dp, then i, j, kif i = 0 and j = 0 and k = 0, then return trueif dp[i, j, k] is not -1, then return dp[i, j, k]ans := falseif j > 0 and k ... Read More
444 Views
Suppose we have a 2D binary matrix where 0s and 1 values are present. We have to find the largest rectangle containing only 1s and return its area.To solve this, we will follow these steps−Define a function called getAns, this will take array acreate stack st, i := 0, ans := 0while i < size of a, thenif stack is empty or a[i] >= top of stack, then insert i into st, increase i by 1otherwise −height := a[top of stack], delete from stackwidth := i when stack is empty, otherwise i – top of st – 1area := height ... Read More
698 Views
Suppose we have a string S and T. We have to find the minimum window in S which will contain all the characters in T. So if the input is like “ABHDAXCVBAGTXATYCB” and T = “ABC”, then the result will be: “CVBA”.To solve this, we will follow these steps −Create one map mstore the frequency of x into mlength := size of s, left := 0, right := 0, ansLeft := 0 and ansRight := 0counter := size of x, flag := false, ans := empty stringwhile height < size of s −c := s[right]if c is present in m, ... Read More
516 Views
Suppose we have two words word1 and word2, we have to find the minimum number of operations required to concert from word1 to word2. The operations can be of three types, these are insert a character, delete a character and replace a character. So if the input strings are “evaluate” and “fluctuate”, then the result will be 5.To solve this, we will follow these steps −n := size of w1, m := size of w2, create an array dp of size n + 1for i in range 0 to ndp[i] := new array of size m + 1for j in ... Read More
2K+ Views
Suppose we have an array of words and a width maxWidth, we have to format the text such that each line has exactly maxWidth number of characters and is fully justified. We should pack our words in a greedy approach; so that is, pack as many words as we can in each line. We will pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.Here extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, empty slots on the left ... Read More
2K+ Views
Suppose we have a set of non-overlapping intervals; we have to insert a new interval into the intervals. We can merge if necessary. So if the input is like − [[1, 4], [6, 9]], and new interval is [2, 5], then the output will be [[1, 5], [6, 9]].To solve this, we will follow these steps −Insert new interval at the end of the previous interval listsort the interval list based on the initial time of the intervals, n := number of intervalscreate one array called ans, insert first interval into ansindex := 1while index < n, last := size ... Read More
907 Views
Suppose we have one array of integers, where all elements are positive. The initial starting point is at index 1. Each element in the array represents our maximum jump length at that position. Our goal is to reach to the final cell with less number of jumps. So if the array is like [2, 3, 1, 1, 4], and then the output will be 2, as we can jump to index 1 from 0, then jump to index 4, that is the last index.To solve this, we will follow these steps −end := 0, jumps := 0, farthest := 0for ... Read More
4K+ Views
Suppose we have an input string s and another input string p. Here is the main string and p is the pattern. We have to define one method, that can match pattern in the string. So we have to implement this for a regular expression, that supports wildcard characters like ‘?’ And ‘*’.Dot ‘?’ Matches any single characterStar ‘*’ Matches zero or more characters.So for example, if the input is like s = “aa” and p = “a?”, then it will be true, for the same input string, if the patter is “?*”, then it will be true.To solve this, ... Read More
1K+ Views
Suppose we have an array of n non-negative integers. These are representing an elevation map where the width of each bar is 1, we have to compute how much water it is able to trap after raining. So the map will be like −Here we can see there are 6 blue boxes, so the output will be 6.To solve this, we will follow these steps −Define a stack st, water := 0 and i := 0while i < size of heightif is stack is empty or height[stack top] >= height[i], then push i into stack, increase i by 1otherwisex := ... Read More