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

2K+ Views
Suppose we have a string consisting of parenthesis and integers. We have to construct a binary tree from that string. The whole input represents a binary tree. It holds an integer that followed by zero, one or two pairs of parentheses. The integer represents the root's value and a pair of parenthesis contains a child binary tree with the same structure.So, if the input is like "4(2(3)(1))(6(5))", then the output will be [3, 2, 1, 4, 5, 6] (inorder traversal)To solve this, we will follow these steps −Define a function solve(), this will take s, idx, if idx >= size ... Read More

169 Views
Suppose we have a picture consisting of black and white pixels, we have to find the number of black pixels, which are present at row R and column C. That is aligned with all the following rules −R and C will contain exactly N black pixelsFor all rows, that have a black pixel at column C, they should be exactly the same as row R.Here the picture is represented by a 2D char array consisting of 'B' and 'W', for the black and white pixels respectively.If the input is like −WBWBBWWBWBBWWBWBBWWWBWBWAnd N = 3, then the output will be 6. ... Read More

236 Views
Suppose we have a grid, here in each cell can have one of three values −value 0 for an empty cell;value 1 for a fresh orange;value 2 for a rotten orange.In every minute, any fresh orange that is adjacent to a rotten orange becomes rotten.We have to find the minimum number of times that must elapse until no cell has a fresh orange. If this is not possible, then return -1.So, if the input is like [[2, 1, 1], [1, 1, 0], [0, 1, 1]], then the output will be 4To solve this, we will follow these steps −minutes := ... Read More

539 Views
Suppose we have a binary tree, the root node is present at depth 0, and children of each depth k node are at depth k+1.Here two nodes of a binary tree are called cousins if they have the same depth, but have different parents.All values of the tree will be unique, and the values x and y of two different nodes in the tree. We have to check whether the nodes corresponding to the values x and y are cousins or not.So, if the input is likex = 5, y = 4, then the output will be trueTo solve this, ... Read More

231 Views
Suppose we are considering an infinite number line, here the position of the i−th stone is given by array stones and stones[i] is indicating ith stone position. A stone is an endpoint stone if it has the smallest or largest position. Now in each turn, we pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.If the stones are at say, stones = [1, 2, 5], we cannot move the endpoint stone at position 5, because moving it to any position (such as 0, or 3) will still keep ... Read More

240 Views
Suppose we have an array A of integers; we have to find the maximum sum of elements in two non−overlapping subarrays. The lengths of these subarrays are L and M.So more precisely we can say that, we have to find the largest V for whichV = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) and either −0 = 0, decrease i by 1, decrease j by 1, do −rightL[i + 1] := max of temp and x where x is 0 if i + 2 >= n otherwise x = rightL[i + 2]temp ... Read More

202 Views
Suppose we have a number n, we have to find the number of trailing zeros of n!.So, if the input is like n = 20, then the output will be 4, as 20! = 2432902008176640000To solve this, we will follow these stepsset count := 0for i := 5, (n/i) > 1, update i := i * 5, docount := count + (n /i)return countLet us see the following implementation to get better understandingExample Live Demo#include #include #define MAX 20 using namespace std; int countTrailingZeros(int n) { int count = 0; for (int i = 5; n / i >= 1; i *= 5) count += n / i; return count; } main() { int n = 20; cout

464 Views
Suppose we have a string with lowercase letters and we also have a list of non-negative values called costs, the string and the list have the same length. We can delete character s[i] for cost costs[i], and then both s[i] and costs[i] is removed. We have to find the minimum cost to delete all consecutively repeating characters.So, if the input is like s = "xxyyx" nums = [2, 3, 10, 4, 6], then the output will be 6, as we can delete s[0] and s[3] for a total cost of 2 + 4 = 6.To solve this, we will follow ... Read More

210 Views
Suppose we have a 2D binary matrix where 1 represents a communication tower, and 0 represents an empty cell. The towers can communicate in the following ways: 1. If tower A, and tower B are either on the same row or column, they can communicate with each other. 2. If tower A can talk with tower B and B can talk with C, then A can talk to C (transitive property). We have to find the total number of tower groups there are (here a group is a list of towers that can talk with each other).So, if the input ... Read More

2K+ Views
Suppose we have two values hours and minutes. We have to find a smaller angle formed between the hour and the minute hand.So, if the input is like hour = 12 minutes = 45, then the output will be 112.5To solve this, we will follow these steps:if h = 12, then set h := 0if m = 60, then set m := 0hAngle := 0.5 * (60h) + mmAngle := 6mret := |hAngle - mAngle|return minimum of ret and (360 – ret)Let us see the following implementation to get better understanding:Example Live Demo#include using namespace std; class Solution { public: ... Read More