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

408 Views
In this tutorial, we will be discussing a program to find the count of numbers having odd number of divisors in a given range.For this we will be provided with the upper and lower limits of the range. Our task is to calculate and count the number of values having an odd number of divisors.Example Live Demo#include using namespace std; //counting the number of values //with odd number of divisors int OddDivCount(int a, int b){ int res = 0; for (int i = a; i

2K+ Views
In this tutorial, we will be discussing a program to find correlation coefficient.For this we will be provided with two arrays. Our task is to find the correlation coefficient denoting the strength of the relation between the given values.Example Live Demo#include using namespace std; //function returning correlation coefficient float find_coefficient(int X[], int Y[], int n){ int sum_X = 0, sum_Y = 0, sum_XY = 0; int squareSum_X = 0, squareSum_Y = 0; for (int i = 0; i < n; i++){ sum_X = sum_X + X[i]; sum_Y = sum_Y + Y[i]; ... Read More

419 Views
In this tutorial, we will be discussing a program to find compound interest.Compound interest is the interest by adding the current interest to the principal sum and then calculating the interest on the updated amount.Example Live Demo#include using namespace std; int main(){ double principle = 10000, rate = 10.25, time = 5; //calculating compound interest double CI = principle * (pow((1 + rate / 100), time)); cout

352 Views
Suppose we have a lowercase alphabet string s, we have to find the length of the shortest substring (minimum length is 2) such that some letter appears more than the other letters combined. If we cannot find any solution, then return -1.So, if the input is like "abbbcde", then the output will be 2, the substring "bb" has minimum length and this appears more than other letters.To solve this, we will follow these steps −Define a function ok(), this will take an array cnt, total := 0, maxVal := 0for each element it in cnt, dototal := total + itmaxVal ... Read More

338 Views
Suppose we have a list of numbers. We have to define a method that can rotate a list of numbers to the left by k elements.So, if the input is like [5, 4, 7, 8, 5, 6, 8, 7, 9, 2], k = 2, then the output will be [8, 5, 6, 8, 7, 9, 2, 5, 4, 7]To solve this, we will follow these steps −Define an array retn := size of numsk := k mod nfor initialize i := k, when i < n, update (increase i by 1), do −insert nums[i] at the end of retfor initialize ... Read More

310 Views
Suppose we have a list of intervals where each interval contains the [start, end] times. We have to find the minimum total size of any two non-overlapping intervals, where the size of an interval is (end - start + 1). If we cannot find such two intervals, return 0.So, if the input is like [[2, 5], [9, 10], [4, 6]], then the output will be 5 as we can pick interval [4, 6] of size 3 and [9, 10] of size 2.To solve this, we will follow these steps −ret := infn := size of vsort the array v based ... Read More

303 Views
Suppose we have a string s containing only '(' and ')', we have to find the minimum number of brackets that can be inserted to make the string balanced.So, if the input is like "(()))(", then the output will be 2 as "(()))(", this can be made balanced like "((()))()".To solve this, we will follow these steps −:= 0, cnt := 0for initialize i := 0, when i < size of s, update (increase i by 1), do −if s[i] is same as '(', then −(increase o by 1)Otherwiseif o is non-zero, then −(decrease o by 1)Otherwise(increase cnt by 1)return ... Read More

378 Views
Suppose we have a singly linked list node containing positive numbers. We have to find the same linked list where every node's next points to the node val nodes ahead. If we cannot find such node, next will be null.So, if the input is like [2, 3, 10, 5, 9], then the output will be [2, 3, 15, ]To solve this, we will follow these steps −Define an array vwhile node is not null, do −insert value of node into vnode := next of noderet = new list node with value 0temp = reti := 0while i < size of ... Read More

180 Views
Suppose we have two binary trees called source and target; we have to check whether there is some inversion T of source such that it is a subtree of the target. So, it means there is a node in target that is identically same in values and structure as T including all of its descendants.As we know a tree is said to be an inversion of another tree if either −Both trees are emptyIts left and right children are optionally swapped and its left and right subtrees are inversions.So, if the input is like sourceTargetthen the output will be TrueTo ... Read More

166 Views
Suppose we have a binary tree root; we have to count the number of nodes where its value is greater than or equal to the values of all of its descendants.So, if the input is likethen the output will be 4 as all nodes except 3, it meets the criteria.To solve this, we will follow these steps −Define a function dfs(), this will take node, if node is not null, then −return 0l := dfs(left of node)r := dfs(right of node)if val of node >= maximum of l and r, then −(increase ret by 1)x := maximum of val of ... Read More