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

610 Views
Suppose we have different k sorted arrays. We have to merge these arrays and display the sorted result.So, if the input is like k = 3 and arrays are {2, 4}, {3, 5, 7}, {1, 10, 11, 12} , then the output will be 1 2 3 4 5 7 10 11 12To solve this, we will follow these steps −define one type of pair with first element is an integer and second element is another pair of integers, name it as ppi.Define an array opdefine one priority queue qfor initialize i := 0, when i < size of arr, ... Read More

254 Views
Suppose we have a binary tree; we have to calculate the length of the longest path which consists of nodes with consecutive values in increasing order. Every node will be treated as a path of length 1.So, if the input is likethen the output will be 3 as (11, 12, 13) is maximum consecutive path.To solve this, we will follow these steps −Define a function solve(), this will take root, prev_data, prev_length, if not root is non-zero, then −return prev_lengthcur_data := val of rootif cur_data is same as prev_data + 1, then −return maximum of solve(left of root, cur_data, prev_length+1) ... Read More

427 Views
we have an array A. A has all elements occurring m times, but one element occurs only once. We have to find that unique element.So, if the input is like A = [6, 2, 7, 2, 2, 6, 6], m = 3, then the output will be 7.To solve this, we will follow these steps −INT_SIZE := 8 * size of an integer type variableDefine an array count of size: INT_SIZE. and fill with 0for initialize i := 0, when i < INT_SIZE, update (increase i by 1), do −for initialize j := 0, when j < size, update (increase ... Read More

383 Views
Suppose we have a binary tree. As we know the succinct encoding of Binary Tree performs close to lowest possible space. The n’th Catalan number is designated by the number of structurally different binary trees with n different nodes. If the n is large, this is about 4n; thus, we require minimum about log2(4) n = 2n bits to encode it. A succinct binary tree therefore would consume 2n + O(n) bits.So, if the input is likethen the output will beencoded −Structure List 1 1 1 0 0 1 0 0 1 0 1 0 0Data List 10 20 40 ... Read More

903 Views
In this problem, we are given a two matrix mat[][]. Our task is to create a program to find the maximum sum of elements from each row in the matrix in C++.Problem DescriptionHere, we will find the maximum sum by taking one element from each row of the matrix in such a way that the element at the current row is greater than the last row element to be considered as a sum. We will find the maximum sum of elements that follows the above condition and print -1 if it is not possible.Let’s take an example to understand the ... Read More

343 Views
In this article, we are given a number N. Our task is to create a program to find the maximum sum of distinct numbers with LCM as N in C++. To achive this first of all we need to find the sum of maximum numbers that have N as the Lowest Common Multiple (LCM). For better understanding Let us go through 3 key concepts − Least Common Multiple (LCM): The lowest common multiple(LCM) of two or more integers is the smallest positive integer that is divisible for all of the integers. For example, the LCM of 4 and 5 ... Read More

189 Views
In this problem, we are a number N. Our task is to create a program to find the Maximum sum of distinct numbers such that LCM of these numbers is N in C++.Problem DescriptionWe need to find the sum of all factors of the number N. And add all distinct to find the maximum sum.Let’s take an example to understand the problem, InputN = 12Output28ExplanationAll distinct factors of N are 1, 2, 3, 4, 6, 12. Sum = 1 + 2 + 3 + 4 + 6 + 12 = 28Solution ApproachA simple solution will be finding all the factors ... Read More

309 Views
In this problem, we are given a number N. Our task is to create a program to find the Maximum sum of difference of adjacent elements in C++.Problem DescriptionWe will find the Maximum sum of the absolute difference between the adjacent elements of all permutation arrays.Let’s take an example to understand the problem, InputN = 4Output7ExplanationAll permutations of size 4 are : {1, 2, 3, 4} = 1 + 1 + 1 = 3 {1, 2, 4, 3} = 1 + 2 + 1 = 4 {1, 3, 2, 4} = 2 + 1 + 2 = 5 {1, 3, ... Read More

591 Views
In this problem, we are given an array. Our task is to create a program to find the Maximum sum of absolute difference of any permutation in C++.Problem DescriptionWe will be finding all permutation of the elements of the given array. And then finding the sum of the absolute difference of adjacent elements of the array. Lastly we will return the maximum of all sums.Let’s take an example to understand the problem, Inputarr[] = {9, 1, 6, 3}Output17ExplanationAll permutations of the array with sum of absolute difference of adjacent elements. {9, 1, 6, 3}, sum= |9-1| + |1-6| + |6-3| ... Read More

145 Views
In this problem, we are given an array arr[] of N elements. Our task is to create a program to find the maximum Sum Increasing Subsequence using Binary Indexed Tree in C++.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 9, 2, 3, 7}Output13ExplanationMaximum increasing subsequence is 1, 2, 3, 7. Sum = 13Solution ApproachTo solve the problem, we will use the Binary Indexed Tree in which we will insert values and map them to binary indexed tree. Then find the maximum value.ExampleProgram to illustrate the working of our solution, Live Demo#include using namespace std; int ... Read More