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

1K+ Views
In this problem, we are given a natural number N. Our task is to find the sum of divisors of all the divisors of a natural number.Let's take an example to understand the problem, Input : N = 12 Output : 55Explanation −The divisors of 12 are 1, 2, 3, 4, 6, 12 Sum of divisors = (1) + (1 + 2) + (1 + 3) + (1 + 2 + 4) + (1 + 2 + 3 + 6) + (1 + 2 + 3 + 4 + 6 + 12) = 1 + 3 + 4 + 7 ... Read More

731 Views
In this problem, we are given an array arr[] consisting of n integer values. Our task is to find the sum of all unique subarray sum for a given array. Subarray sum is the sum of elements of the given subarray.Let's take an example to understand the problem, Input : arr[] = {1, 2, 4} Output : 23Explanation −All subarrays of the given array are : (1), (2), (4), (1, 2), (2, 4), (1, 2, 4) Sum of subarrays = 1 + 2 + 4 + (1+2) + (2+4) + (1+2+4) = 23Solution ApproachA solution to the problem is by ... Read More

425 Views
In this problem, we are given a binary tree. Our task is to find the sum of all left right in a given Binary Tree.Let's take an example to understand the problem, Input :Output : 8Explanation −All leaf nodes of the tree are : 1, 8 Sum = 1 + 8 = 9Solution ApproachA simple solution to the problem is traversing the tree from root to leaf. If a node is a left leaf node, add it to sum. When the whole tree is traversed. Print Sum.ExampleProgram to illustrate the working of our solution#include using namespace std; struct Node{ ... Read More

396 Views
In this problem, we are given a binary tree. Our task is to find the sum of all left leaves in a given Binary Tree.Let's take an example to understand the problem, Input : Output : 11Explanation −All leaf nodes of the tree are : 2, 9 Sum = 2 + 9 = 11Solution ApproachA simple solution to the problem is traversing the tree from root to leaf. If a node is a left leaf node, add it to sum. When the whole tree is traversed. Print Sum.ExampleProgram to illustrate the working of our solution#include using namespace std; struct Node{ ... Read More

590 Views
In this problem, we are given an array arr[] consisting of N integers stored in unsorted order. Our task is to find a subarray with a given sum.Let's take an example to understand the problem, Input : arr[] = {2, 5, -1, 4, 6, -9, 5} sum = 14 Output : subarray = {5, -1, 4, 6}Explanation −Subarray sum = 5 - 1 + 4 + 6 = 14Solution ApproachA simple solution to the problem is using nested loops. We will loop through the array and using an inner loop, we will find subarray. For each subarray we will find ... Read More

412 Views
In this problem, we are given an array arr[] consisting of N positive integers stored in unsorted order. Our task is to find a subarray with a given sum.Let's take an example to understand the problem, Input : arr[] = {2, 5, 1, 4, 6, 9, 5} sum = 11 Output : subarray = {1, 4, 6}Explanation −Subarray sum = 1 + 4 + 6 = 11Solution ApproachA simple solution to the problem is using nested loops. We will loop through the array and using an inner loop, we will find subarray. For each subarray we will find the sum ... Read More

259 Views
In this problem, we are given a string str and an integer pow. Our task is to find a sub-string with given power.We need to return the substring whose power is equal to pow.Power of string is the sum of powers of its characters.Power of character : a -> 1, b -> 2, c -> 3, ...Let's take an example to understand the problem, Input : string = "programming" power = 49 Output : 'pro'Explanation −Power of matrix : pro, power(p) = 16 power(p) = 18 power(p) = 15 Total = 16 + 18 + 15 = 49Solution ApproachA simple ... Read More

1K+ Views
In this problem, we are given a 2D matrix of size N*N and two variables sum and size. Our task is to find a sub-matrix with the given sum.We need to find a sub-matrix of size*size with element sum equal to sum.Let's take an example to understand the problem, Input : mat[][] = { {1, 5, 7, 9} {2, 4, 6, 8} {1, 2, 5, 6} {3, 6, 9, 3} } sum = 22 Size = 2 Output : YESExplanation −The submatrix of size k with sum 22 is {5, 7} {4, 6}Solution ApproachA simple solution ... Read More

933 Views
In this problem, we are given an array aar[] of n integer values which are not sorted and an integer val. Our task is to find the start and ending index of an element in an unsorted array.For the occurrence of the element in the array, we will return, "Starting index and ending index " if it is found in the array twice or more."Single index " if it is found in the array once."Element not present " if it is not present in the array.Let's take an example to understand the problem, Example 1Input : arr[] = {2, 1, ... Read More

580 Views
In this problem, we are given two values n and a prime number p. Our task is to find Square Root under Modulo p.Let's take an example to understand the problem, Input : n = 4, p = 11 Output : 9Solution ApproachHere, we will be using Tonelli-Shanks Algorithm.Tonelli-Shanks Algorithm is used in modular arithmetic to solve for a value x in congruence of the form x2 = n (mod p).The algorithm to find square root modulo using shank's Tonelli Algorithm −Step 1 − Find the value of $(n^{((p-1)/2)})(mod\:p)$, if its value is p -1, then modular square root is ... Read More