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

170 Views
Suppose we have a number N. We have another number k. We have to check the number can be represented using k numbers or not. Suppose a number 54, and k = 3, then it will print the numbers like [2, 3, 9], if it cannot be represented, then print that.To solve this, we will find all prime factors of N, and store them into a vector, then to find k numbers greater than 1, we check the size of the vector is greater than k or not. If size is less than k, then return -1, otherwise print first ... Read More

177 Views
Suppose we have an array A. We have to check whether we can split the array into two parts, whose sum are equal. Suppose the elements are [6, 1, 3, 2, 5], then [6, 1], and [2, 5] can be two subarrays.This problem can be solved easily by following these rules. We have to find the sum of all elements of the array at first, then for each element of the array, we can calculate the right sum by using total_sum – sum of elements found so far.Example#include #include using namespace std; void displaySubArray(int arr[], int left, int right) { cout

354 Views
Here we will see how to find the frequency of smallest element in an array. Suppose the array elements are [5, 3, 6, 9, 3, 7, 5, 8, 3, 12, 3, 10], here smallest element is 3, and the frequency of this element is 4. So output is 4.To solve this we will find the smallest element of the list, then we count the occurrences of first numbers, and that will be the result.Example#include using namespace std; int min_element(int arr[], int n){ int min = arr[0]; for(int i = 1; i

263 Views
We know that the excel column numbers are alphabetic. It starts from A, and after Z, it will AA, AB, to ZZ, then again AAA, AAB, to ZZZ and so on. So column 1 is A, column 27 is Z. Here we will see how to get the column letter if number of column is given. So if the column number is 80, then it will be CB.Suppose we have a number n, and its value is 28, then we need to take reminder with 26. If the remainder is 0, then the number is 26, 52 and so on. ... Read More

169 Views
Suppose we have two arrays A and B. There are few elements. We have to find those elements that are present in set A, but not in set B. If we think that situation, and consider A and B as set, then this is basically set division operation. The set difference between A and B will return those elements.Example#include #include #include #include using namespace std; void setDiffResults(int A[], int B[], int An, int Bn) { sort(A, A + An); sort(B, B + Bn); vector res(An); vector::iterator it; vector::iterator it_res = set_difference(A, A + An, B ... Read More

326 Views
Consider we have to find a list of n elements. But we have the XOR value of two consecutive elements of the actual array. Also the first element of the actual is given. So if the array elements are a, b, c, d, e, f, then the given array will be a^b, b^c, c^d, d^e and e^f.As the first number is given, named a, that can help us to find all numbers. If we want to find the second element of the actual array, then we have to perform b = a ^ arr[i], for second element c = b ... Read More

184 Views
Suppose we have a list with 6 different numbers. Only one number is repeated five times. So there are total 10 elements in the array. Find duplicate numbers using only two comparisons. If the list is like [1, 2, 3, 4, 4, 4, 4, 4, 5, 6], so output is 4.As there are only 10 numbers, then for any type of duplicate numbers, the range of numbers will be placed from index 3 to 5. By checking these indices, we can find the result.Example#include using namespace std; int getDuplicate(int array[]) { if (array[3] == array[4]) return array[3]; else if (array[4] == array[5]) return array[4]; else return array[5]; } int main() { int a[] = {1, 2, 3, 4, 4, 4, 4, 4, 5, 6}; cout

154 Views
In this tutorial, we will be discussing a program to print the nodes present at the odd levels of a given binary tree.In this program, the level for the root node is considered as 1 and simultaneously the alternative level is the next odd level.For example, let us say we are given with the following binary treeThen the nodes at the odd levels of this binary tree will be 1, 4, 5, 6.Example#include using namespace std; struct Node { int data; Node* left, *right; }; //printing the nodes at odd levels void print_onodes(Node *root, bool is_odd = ... Read More

325 Views
Suppose we have a list of numbers from 0 to n-1. A number can be repeated as many as possible number of times. We have to find the repeating numbers without taking any extra space. If the value of n = 7, and list is like [5, 2, 3, 5, 1, 6, 2, 3, 4, 5]. The answer will be 5, 2, 3.To solve this, we have to follow these steps −for each element e in the list, do the following steps −sign := A[absolute value of e]if the sign is positive, then make it negativeOtherwise it is a repetition.Example#include ... Read More

393 Views
In this tutorial, we will be discussing a program to print the longest path that exists from a leaf node to another leaf node in a given binary tree.In other words, we have to print all the nodes that appear in the diameter of the Binary tree. Here, diameter (or width) for a particular binary tree is defined as the number of nodes in the longest path from one end node to another.To solve this, we calculate the diameter of the binary tree using the height function. Then we find the longest path in the left portion of the binary ... Read More