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

125 Views
Suppose we have n points on x-axis and the list of allowed translation between the points. Find if it is possible to reach the end from starting point through these transactions only. So if there is a translation between points x1 and x2, then we can move from point x to any intermediate points between x1 and x2, or directly to x2. So if n = 5. And transactions are 0 to 2, 2 to 4, and 3 to 5. Then output will be YES. There is a path from 0→2→3→5.We have to sort the list according to the first ... Read More

141 Views
Suppose we have two binary trees. We have to find first leaf of two trees, that does not match. If there are no non-matching leaves, then display nothing.If these are two trees, then the first non-matching leaves are 11 and 15.Here we will use the iterative preorder traversal of both of the trees simultaneously using stack. We will use different stack for different trees. We will push nodes into the stack till the top node is the leaf node. Compare two top, if they are same, then do further checking, otherwise show two stack top elements.Example Live Demo#include #include ... Read More

155 Views
Suppose we have one sorted array with n elements. The array is sorted. We have to find whether an element exists in an array from where the number of smaller element is same as the number of larger elements. If the equal point appears multiple times in the array, return the index of first occurrence. If no such point is present, then return -1. Suppose the elements are like A = [1, 1, 2, 3, 3, 3, 3, 3], then the equal point is at index 2, the element is A[2] = 2. As it has only one smaller element ... Read More

290 Views
Consider we have the selling price, and percentage of profit or loss is given. We have to find the cost price of the product. The formula is like below −$$Cost \: Price = \frac{Sell Price * 100}{100 + Percentage \: Profit}$$$$Cost \: Price = \frac{Sell price *100}{100 + percentage\:loss}$$Example Live Demo#include using namespace std; float priceWhenProfit(int sellPrice, int profit) { return (sellPrice * 100.0) / (100 + profit); } float priceWhenLoss(int sellPrice, int loss) { return (sellPrice * 100.0) / (100 - loss); } int main() { int SP, profit, loss; SP = 1020; profit = 20; cout

255 Views
Suppose we have an arithmetic expression without parentheses. Our task is to find all possible outcomes of that expression. Suppose the expression is like 1+2*3-4, this can be interpreted like below −1+(2*(3-4)) = 1 + (2* -1) = -1(1+2)*(3-4) = 3 * -1 = -31+((2*3)-4) = 1 + (6 - 4) = 3((1+2)*3)-4 = (3 * 3) - 4 = 51+(2*3)-4 = 1 + 6 – 4 = 3To solve this problem, we have to follow these steps −Initially set res as emptyFor every operator x, do the following −Recursively evaluate all possible values on left of x, let the ... Read More

157 Views
Suppose we have a n ranges containing L and R. We have to check or find the index of 0 – based of the range which covers all the other given n – 1 ranges. If there is no such range, display -1. For example, if L = [2, 4, 3, 1], and R = [4, 6, 7, 9], then the output is 3. So it means the range at 3rd index (1 to 9) covers all the elements of other n – 1 ranges.Since all L and R points are distinct, find the range of smallest L and largest ... Read More

296 Views
Suppose we have a number n. We have to find the range of positive integers, where all the numbers in the range is composite, and the length of the range is n. If there are more than one range, then print any one range. The composite number is a number where it has at least one divisor other than 1 and itself.As the length of the range is n, then if the first number is a, then the other numbers are a + 1, a + 2, …, a + n – 1, all should be composite. If we see ... Read More

104 Views
Suppose we have two integers N and K. We have to find first permutation of 2N number of natural numbers, such that the following equation is satisfied.$$\displaystyle\sum\limits_{i=1}^N\lvert A_{2i-1}-A_{2i}\rvert+\lvert \displaystyle\sum\limits_{i=1}^N A_{2i-1}-A_{2i} \rvert=2K$$The value of K should be less than or equal to N. For example, if N = 4 and K = 1, then output will be 2 1 3 4. The result of the given expression will be (|2 – 1| + |3 – 4|) – (|2 – 1 + 3 – 4|) = 2.The idea is simple, consider we have a sorted sequence like 1, 2, 3, 4, 5, ... Read More

483 Views
Suppose we have an array A with n elements. We have to find the local minima of the array. In array A, the element A[x] is said to be local minima if it is less than or equal to both of its neighbors. For corner elements only one neighbor will be considered. And if there are more than one local minima available, then return only one. For example, if the array is like [9, 6, 3, 14, 5, 7, 4], then the local minima can be 3, 5 and 4, so this algorithm can return only one of them.To solve ... Read More

465 Views
Here we will see how to compare two strings in C++. The C++ has string class. It also has the compare() function in the standard library to compare strings. But here we will use the conditional operators like ==, !=, , =. These operators check the strings character by characters. Let us see the code to get better idea.Example Live Demo#include using namespace std; void compareStrings(string s1, string s2) { if (s1 != s2) cout