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

115 Views
Suppose we have a number n, and we have to find the permutation of this number, that is divisible by 3, but not divisible by 6. If no such value can be made, then return -1. For example, if n is 336, then the output can be 363.As we know a number is divisible by 6 means it is divisible by 3 and 2. So each even number that is divisible by 3, will be divisible by 6. If we interchange the digits of a number which is divisible by 3 and also even, to make it odd, it will ... Read More

136 Views
Suppose we have three integers, a, b and x. The task is to get the multiple of x, which is closest to ab. So if a = 5, b = 4 and x = 3, then output will be 624. As 54 = 625, and 624 is the multiple of 3, which is closest to 625.The task is simple. we have to follow these steps to solve this problem −calculate num := abThen find f := floor of (num/x)Now the closest element at the left will be cl = x * f, and at right will be cr = x ... Read More

152 Views
Suppose we have an array that represents elements of geometric progression in order. One element is missing. We have to find the missing element. So if arr = [1, 3, 27, 81], output is 9, as 9 is missing.Using binary search, we can solve this problem. We will go to the middle element, then check whether the ratio between middle and next to the middle is same as common ratio or not. If not, then missing element is present between indices mid and mid + 1. If the middle element is the n/2th element in the GP, then missing element ... Read More

129 Views
Suppose we have one matrix or order NxN. We have to find a pair of elements which forms maximum difference from any column of the matrix. So if the matrix is like −123535967So output will be 8. As the pair is (1, 9) from column 0.The idea is simple, we have to simply find the difference between max and min elements of each column. Then return max difference.Example#include #define N 5 using namespace std; int maxVal(int x, int y){ return (x > y) ? x : y; } int minVal(int x, int y){ return (x > y) ? ... Read More

203 Views
Suppose we have an array that represents elements of arithmetic progression in order. One element is missing. We have to find the missing element. So if arr = [2, 4, 8, 10, 12, 14], output is 6, as 6 is missing.Using binary search, we can solve this problem. We will go to the middle element, then check whether the difference between middle and next to the middle is same as diff or not. If not, then missing element is present between indices mid and mid + 1. If the middle element is the n/2th element in the AP, then missing ... Read More

306 Views
Suppose we have a number N, and unlimited number of coins worth 1, 10 and 25 currency coins. Find minimum number of coins we need to use to pay exactly amount N. Suppose N is 14, then number of coins will be 5, as one 10 value coin and four 1 value coin.To solve this, we have to use these steps −If N < 10, then return N number of 1 value coinsIf N > 9 and N < 25, then divide the value with 10, and get the result, the remaining will be covered using 1 value coin, add ... Read More

859 Views
Suppose we have two integers N and M. We have to find minimum number of steps to reach M from N, by performing given operations −Multiply the number x by 2, so x will be 2*xSubtract one from the number x, so the number will be x – 1If N = 4 and M = 6, then output will be 2. So if we perform operation number 2 on N, then N becomes 3, then perform operation number one on updated value of N, so it becomes 2 * 3 = 6. So the minimum number of steps will be ... Read More

405 Views
Suppose we have a number n, and we have to find the number of diagonals for n sided convex polygon. So if the n = 5, then diagonals count will be 5.As this is n-sided convex polygon, from each vertex we can draw n – 3 diagonals leaving two sided adjacent vertices and itself. So for n vertices, it will be n*(n-3), but as we are considering twice, so it will be n(n – 3)/2.Example Live Demo#include using namespace std; int diagonalCount(int n) { return n * (n - 3) / 2; } int main() { int n = 8; cout

1K+ Views
Suppose we have one unsorted array A, and two numbers x and y. We have to find the minimum distance between x and y in A. The array can also contain duplicate elements. So if the array is A = [2, 5, 3, 5, 4, 4, 2, 3], x = 3 and y = 2, then the minimum distance between 3 and 2 is just 1.To solve this, we have to follow these steps, Traverse the array from left to right and stop if either x or y has found. Then store the index of that position into prevNow traverse ... Read More