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

138 Views
In this tutorial, we will be discussing a program to find maximum sum alternating subsequence.For this we will be provided with an array of integers. Our task is to find the maximum sum of an alternating subsequence i.e sequence which is first decreasing, then increasing, then decreasing and so on.Example Live Demo#include using namespace std; //returning maximum sum alternating series int maxAlternateSum(int arr[], int n) { if (n == 1) return arr[0]; int dec[n]; memset(dec, 0, sizeof(dec)); int inc[n]; memset(inc, 0, sizeof(inc)); dec[0] = inc[0] = arr[0]; int flag = 0 ; for (int i=1; i

199 Views
In this tutorial, we will be discussing a program to find maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST.For this we will be provided with a binary tree. Our task is to print the sum of a sub-tree which is also a binary search tree.Example Live Demo#include using namespace std; //creating binary tree node struct Node { struct Node* left; struct Node* right; int data; Node(int data) { this->data = data; this->left = NULL; this->right = NULL; } }; struct Info ... Read More

351 Views
In this tutorial, we will be discussing a program to find maximum subsequence sum such that no three are consecutive.For this we will be provided with a series of positive integers. Our task is to find the maximum sum without taking in their consecutive positive integers in the sum value.Example Live Demo#include using namespace std; //returning maximum subsequence without involving //three consecutive numbers int maxSumWO3Consec(int arr[], int n) { int sum[n]; if (n >= 1) sum[0] = arr[0]; if (n >= 2) sum[1] = arr[0] + arr[1]; if (n > 2) sum[2] = max(sum[1], max(arr[1] + arr[2], ... Read More

104 Views
In this tutorial, we will be discussing a program to find maximum sub-matrix area having count of 1’s one more than count of 0’s.For this we will be provided with a matrix containing 0’s and 1’s. Our task is to get the sub-matrix of maximum area containing more 1’s than 0’sExample Live Demo#include using namespace std; #define SIZE 10 //finding length of longest sub-matrix int lenOfLongSubarr(int arr[], int n, int& start, int& finish) { unordered_map um; int sum = 0, maxLen = 0; for (int i = 0; i < n; i++) { sum ... Read More

123 Views
In this tutorial, we will be discussing a program to find maximum subarray sum in an array created after repeated concatenation.For this we will be provided with an array and an integer K. Our task is to find the subarray with the maximum elements when the given array is repeated K times.Example Live Demo#include using namespace std; //returning sum of maximum subarray int maxSubArraySumRepeated(int a[], int n, int k) { int max_so_far = INT_MIN, max_ending_here = 0; for (int i = 0; i < n*k; i++) { max_ending_here = max_ending_here + a[i%n]; if ... Read More

138 Views
In this tutorial, we will be discussing a program to find maximum Subarray Sum Excluding Certain Elements.For this we will be provided with two arrays of size M and N. Our task is to find a sub-array in the first array such that no element inside the subarray is present inside the second array and the elements of subarray sum up to be maximum.Example Live Demo#include using namespace std; //checking if element is present in second array bool isPresent(int B[], int m, int x) { for (int i = 0; i < m; i++) if (B[i] == x) ... Read More

156 Views
In this tutorial, we will be discussing a program to find maximum subarray size, such that all subarrays of that size have sum less than k.For this we will be provided with an array of size N and an integer k. Our task is to find the length of subarray such that all the sub-arrays of that length in the given array sum to be less than or equal to k.Example Live Demo#include using namespace std; //finding maximum length subarray int bsearch(int prefixsum[], int n, int k) { int ans = -1; //performing binary search int left = ... Read More

151 Views
In this tutorial, we will be discussing a program to find maximum students to pass after giving bonus to everybody and not exceeding 100 marks.For this we will be provided with an array containing marks of N students. Our task is to get more student pass the exam (50 marks required) by giving each student the same amount of bonus marks without any student exceeding 100 marks.Example Live Demo#include #include using namespace std; int check(int n, int marks[]) { int* x = std::max_element(marks, marks+5); int bonus = 100-(int)(*x); int c = 0; for(int i=0; i= 50) ... Read More

198 Views
Suppose we have an array of 4 digits, we have to find the largest 24-hour time that can be made. We know that the smallest 24-hour time is 00:00, and the largest time is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight. We have to return the answer as a string of length 5. If there is no valid time to be returned, then return an empty string.So, if the input is like [1, 2, 3, 4], then the output will be "23:41"To solve this, we will follow these steps −Define a function ... Read More

301 Views
Suppose we have a deck of cards, each card has an integer written on it. We have to check whether we can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where the following condition satisfies: Each group has exactly X number of cards. All of the cards in each group have the same number.So, if the input is like deck = [1, 2, 3, 4, 4, 3, 2, 1], then the output will be True, as possible partitions are [1, 1], [2, 2], [3, 3], [4, 4].To ... Read More