- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7347 Articles for C++
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
177 Views
In this problem, we are given an array consisting of (2n+ 1) integer values. Out of all these values, n elements appear twice in the array and there is only one element in the array that appears once. Our task is to Find single in an array of 2n+1 integer elements.Let’s take an example to understand the problem, Inputarr[] = {1, 3, 5, 6, 5, 1, 3}Output5Solution ApproachA simple solution to the problem is using a counter for the elements. If an element is encountered, store its value and occurrence count. After this search for the element in the table ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
149 Views
In this problem, we are given an array of words arr[]. Our task is to find the shortest unique prefix for every word in the given list.Let’s take an example to understand the problem, Inputarr[] = {“learn”, “programming”, “code”}Outputc leap lear pSolution ApproachA simple solution to the problem is by finding all the prefixes of the word. And then check if it is a prefix of any other word in the array. If it is not, print it.An efficient approach is to use the trie data structure. We will construct a trie and store all words. Then find the frequency ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
712 Views
In this problem, we are given a matrix mat[][]. It defines a path with landmines which are marked as 0. Our task is to Find shortest safe route in a path with landmines.While traversing through the safe path, we need to avoid walking adjacent cells of the landmine (left, right, above and bottom) for being unsafe.All valid moves while traversing the path are −- Left : mat[i][j] => mat[i-1][j] - Right : mat[i][j] => mat[i+1][j] - Top : mat[i][j] => mat[i][j - 1] - Bottom : mat[i][j] => mat[i][j + 1]Let’s take an example to understand the problem, Inputmat[][] = ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
910 Views
In this problem, we are given a matrix mat[][] of size N*N. Our task is to Find the row with maximum sum in a Matrix.Let’s take an example to understand the problem, Inputmat[][] = { 8, 4, 1, 9 3, 5, 7, 9 2, 4, 6, 8 1, 2, 3, 4 }OutputRow 2, sum 24ExplanationRow 1: sum = 8+4+1+9 = 22 Row 2: sum = 3+5+7+9 = 24 Row 3: sum = 2+4+6+8 = 20 Row 4: sum = 1+2+3+4 = 10Solution ApproachA simple solution to the problem is to find the sum of elements of ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
115 Views
In this problem, we are given a binary matrix in which each row is sorted. Our task is to Find row number of a binary matrix having the maximum number of 1s.Let’s take an example to understand the problem, InputbinMat[][] = { 1, 1, 1, 1 0, 0, 0, 0 0, 0, 0, 1 0, 0, 1, 1 }Output1Solution ApproachA simple solution to the problem is to count the total number of 1’s in each row. And then return the row number with maximum 1 count.Program to illustrate the working of our solution, Example Live Demo#include ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
177 Views
In this problem we are given a binary tree and parent pointers. Our task is to Find right sibling of a binary tree with parent pointers.Let’s take an example to understand the problem, InputNode = 3Output7Solution ApproachA simple solution to the problem is finding the leaf node of the nearest ancestor (which is neither the current node nor the parest of the current node) which is at the same level as the current node. This is done by counting the levels while going up and then when coming down counting them down. And then finding the node.Program to illustrate the ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
106 Views
In this problem we are given five values m, n, mth term, nth term, p. Our task is to Find Pth term of a GP if Mth and Nth terms are given.For a GP, we are given the values of mth term and nth term. Using these values, we need to find the Pth term of the series.Let’s take an example to understand the problem, Inputm = 7, mthTerm = 1458, n = 10, nthterm = 39366, p = 3Output18Solution ApproachHere, we are given a GP. let's suppose the GP is, GP = a , a*r , a*(r2), a*(r3) ….The ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
131 Views
In this problem we are given four values p, q, r, s. Our task is to Find probability that a player wins when probabilities of hitting the target are given.Here, we have two players who are playing a game of archery. And the probability of player 1 hitting the target is defined as p/q. The probability of player 2 hitting the target is defined as r/s. We need to find the probability of player one winning the game.Let’s take an example to understand the problem, Inputp = 3, q = 5, r = 2, s = 5Output0.789Solution Approach*This approach requires ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
483 Views
In this problem we are given four values A, B, C, M(a prime number). Our task is to Find power of power under mod of a prime.We simply need to find the value of (A ^ (B ^ C)) (mod M).Let’s take an example to understand the problem, InputA = 3, B = 6, C = 2, M = 11Output3Explanation(A ^ (B ^ C)) = (3 ^ (6 ^ 2)) = (3 ^ (36))(mod 11) = 3Solution ApproachA simple solution to the problem is by directly calculating the values of the (A ^ (B ^ C)) , which is done ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
1K+ Views
In this problem we are given an array preOrder[] that represents the preorder traversal of the binary search tree. Our task is to Find postorder traversal of BST from preorder traversal.Let’s take an example to understand the problem, InputpreOrder[] = {5, 2, 4, 7, 12}Output{4, 2, 12, 7, 5}Solution ApproachA simple solution to the problem is to create a BST from the given preorder traversal. And then do postorder traversal of the tree. This solution is Ok but a more effective solution is, We will traverse the preorder array with a limit on values to separate values of left and ... Read More