
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
Found 7197 Articles for C++

197 Views
Suppose we have strings S and T. We have to count number of distinct sequences of S which is equal to T.We know that a subsequence of a string is a new string which is formed from the original string by removing some (can be none) of the characters without disturbing the relative positions of the remaining characters. (Like, "ACE" is a subsequence of "ABCDE" while "AEC" is not).If the input strings are “baalllloonnn” and “balloon”, then there will be 36 different ways to select.To solve this, we will follow these steps −n := size of s, m := size ... Read More

338 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

492 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

427 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

680 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

503 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

17K+ Views
Suppose we have a Sudoku grid and we have to solve this famous number maze problem, Sudoku. We know that Sudoku is a 9 x 9 number grid, and the whole grid are also divided into 3 x 3 boxes There are some rules to solve the Sudoku.We have to use digits 1 to 9 for solving this problem.One digit cannot be repeated in one row, one column or in one 3 x 3 box.Using backtracking algorithm, we will try to solve Sudoku problem. When some cell is filled with a digit, it checks whether it is valid or not. ... Read More

180 Views
Suppose we have a string, s, and we also have a list of words, words present in the array are all of the same length. We have to find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.So if the input is like “barfoothefoobarman” and words are [“foo”, “bar”], then the output will be [0, 9]. This is because the substring starting at index 0 and 9 are “barfoo” and “foobar”.To solve this, we will follow these steps −Define a method called ok(), this will take ... Read More