
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++

389 Views
Suppose there are n people whose IDs are in range 0 to n - 1 and each person belongs exactly to one group. We have the array groupSizes of length n. This array is indicating that the group size each person belongs to, we have to find the groups there are and the people's IDs each group includes.Suppose the input is like − [3, 3, 3, 3, 3, 1, 3], then the output is [[5], [0, 1, 2], [3, 4, 6]], Other possible solutions can be [[2, 1, 6], [5], [0, 4, 3]] or [[5], [0, 6, 2], [4, 3, ... Read More

186 Views
Suppose we a binary matrix, of size m x n. We have to count number of square submatrices, with all 1s. So if the matrix is like −011111110111So there will be 15 squares. 10 squares of single ones, 4 squares of four ones, and 1 square with nine ones.To solve this, we will follow these steps −set ans := 0, n := row count and m := column countfor i in range 0 to m – 1ans := ans + matrix[n – 1, i]for i in range 0 to n – 1ans := ans + matrix[i, m – 1]ans := ... Read More

308 Views
Suppose we have two integers tomatoSlices and cheeseSlices. These are the ingredients of different burgers −Jumbo Burger: 4 tomato slices and 1 cheese slice.Small Burger: 2 Tomato slices and 1 cheese slice.We have to find [total_jumbo, total_small] so that the number of tomatoSlices that are left is equal to 0 and the number of cheeseSlices that are left is also 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return []. So if the input is tomatoSlices = 16 and chesseSlices = 7, then the output will be [1, 6]. So this indicates, ... Read More

456 Views
Suppose we have an array nums of integers, we need to find the maximum possible sum of elements of the given array such that it is divisible by three. So if the input is like [3, 6, 5, 1, 8], then the output will be 18, as the subarray is [3, 6, 1, 8], and the sum is 18, that is divisible by 3.To solve this, we will follow these steps −n := size of nums arraycreate one 2d array dp of size (n + 1) x 3set dp[0, 0] := 0, dp[0, 1] := -inf, dp[0, 2] := inffor ... Read More

187 Views
Suppose we have some lists of regions where the first region of each list includes all other regions in that list. basically, if a region X contains another region Y then, X is larger than Y. Also by definition a region X contains itself. So if we have two regions r1 and r2, we have to find the smallest region that contains both of them. So if we have r1, r2 and r3 such that r1 includes r3, it is guaranteed there is no r2 such that r2 includes r3. So if the input is like [["Earth", "North America", "South ... Read More

577 Views
Suppose we have a non-negative integer n, and we have to find the encoded form of it. The encoding strategy will be as follows −NumberEncoded number0“”1“0”2“1”3”00”4”01”5”10”6”11”7”000”So if the number is 23, then result will be 1000, if the number is 54, then it will be 10111To solve this, we will follow these steps −Create one method called bin, this will take n and k, this method will act like belowres := empty stringwhile n > 0res := res + the digit of n mod 2n := n /2reverse the number reswhile x > length of resres := prepend 0 with ... Read More

227 Views
Suppose we have the following details of a matrix with n columns and 2 rows −Matrix elements will be either 0 or 1Sum of elements of the 0-th(upper) row is given as upper.Sum of elements of the 1-st(lower) row is given as lower.Sum of elements in the i-th column(0-indexed) is colsum[i], where colsum is given as an integer array with length n.The task is to reconstruct the matrix with upper, lower and colsum. We have to find it as a 2D integer array. If there are more than one valid solution, any of them will be accepted. If there is ... Read More

424 Views
Suppose we have an array of strings arr. The string s is a concatenation of a sub-sequence of arr which have unique characters. Find the maximum possible length of s. If the input is like [“cha”, “r”, “act”, “ers”], then the output will be 6, possible solutions are “chaers” and “acters”.To solve this, we will follow these steps −make one method called ok() and this will take strings s and t. This will act like belowmake one map xfor i in range 0 to size of sincrease x[s[i]] by 1if x[s[i]] > 1, then return falsefor i in range 0 ... Read More

241 Views
Suppose we have 2 integers n and start. Our task is return any permutation p of (0, 1, 2....., 2^n -1) as follows −p[0] = startp[i] and p[i+1] differ by only one bit in their binary representation.p[0] and p[2^n -1] must also differ by only one bit in their binary representation.So if the input is like n = 2 and start = 3, then the returned array will be [3, 2, 0, 1], these are [11, 10, 00, 01]To solve this, we will follow these steps −ans is an arrayfor i in range 0 to 2^ninsert start XOR i XOR ... Read More

480 Views
Suppose we have a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'. A string will be balanced if each of its characters appears n/4 times where n is the length of the string. Find the minimum length of the substring that can be replaced with any other string of the same length to make the original string is balanced. So if s = “QQWE”, then output will be 1. This is because we can replace Q to R, so that “RQWE”, that is balanced.Return 0 if the string is already balanced.To solve this, we will follow ... Read More