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

165 Views
In this problem, we are given an array arr[] of N integers and two index values x and y. Our task is to create a program to find the Maximum sum increasing subsequence from a prefix and a given element after prefix is must in C++.Problem DescriptionWe will find the maximum sum of increasing sequence till index x and including the element at index y.Let’s take an example to understand the problem, Inputarr[] = {1, 5, 9, 131, 6, 100, 11, 215}, x = 4, y = 6Output26ExplanationWe will take the subsequence till index 3 and then at last include ... Read More

156 Views
In this tutorial, we will be discussing a program to find maximum Sum Increasing Subsequence.For this we will be provided with an array containing N integers. Our task is to pick up elements from the array adding to the maximum sum such that the elements are in sorted orderExample Live Demo#include using namespace std; //returning the maximum sum int maxSumIS(int arr[], int n) { int i, j, max = 0; int msis[n]; for ( i = 0; i < n; i++ ) msis[i] = arr[i]; for ( i = 1; i < n; ... Read More

352 Views
In this problem, we are given a circular array cirArr[]. Our task is to create a program to find the Maximum sum in circular array such that no two elements are adjacent in C++.Problem DescriptionFor the circular array, we need to find the maximum sum sum of elements of the array such that adjacent elements cannot be taken i.e. we need to take alternate elements.Circular Array is a special type of array in which the last element of the array is connected to the first element.Let’s take an example to understand the problem, InputcirArr[] = {4, 1, 5, 3, 2}Output9ExplanationThe ... Read More

366 Views
In this problem, we are given a rectangular grid of size 2 x n. Our task is to create a program to find the Maximum sum in a 2 x n grid such that no two elements are adjacent in C++.Problem DescriptionTo find the maximum sum, we cannot select elements that are adjacent to the current element, vertically, horizontally or diagonally.Let’s take an example to understand the problem, InputrectGrid[2][] =389 411Output13Explanationall possible sums areIf we start from rectGrid[0][0] i.e. 3, then we can add only 9 or 1. The maxSum is 12.If we start from rectGrid[1][0] i.e. 4, then we ... Read More

340 Views
In this problem, we are given three arrays arr1[], arr2[], and arr3[] all of size N. Our task is to create a program to find the Maximum sum from three arrays such that picking elements consecutively from same is not allowed in C++.Problem DescriptionWe will find the maximum sum by choosing N elements. i=th element can be chosen of the sum from the i-th element of the array i.e. ith sum is from arr1[i]/ arr2[i]/ arr3[i]. Also, keep in mind that we cannot choose two consecutive elements that can be chosen from the same array.Let’s take an example to understand ... Read More

154 Views
In this problem, we are given a binary tree consisting of positive numbers. Our task is to create a program to find the Maximum sum from a tree with adjacent levels not allowed in C++.Code DescriptionHere, we will find the maximum sum of node of the tree in such a way that the sum does not contain nodes from two adjacent levels of the tree.Let’s take an example to understand the problem, Output21ExplanationTaking root as starting level, sum = 5 + 3 + 8 + 1 = 17 Taking sub-child of root as starting level, sum = 2 + 6 ... Read More

177 Views
Suppose we have three integers n, m, and k. If we have following algorithm to find the maximum element of an array of positive integers −max_val := -1 max_ind := -1 search_cost := 0 n := size of arr for initialize i := 0, when i < n, update (increase i by 1), do: if max_val < arr[i], then: max_val := arr[i] max_ind := i (increase search_cost by 1) return max_indWe have to make the array arr which has the following criteria: arr has exactly n integers. all elements arr[i] are in range 1 to m(including) (0

166 Views
Suppose we have a grid whose size is n x 3 and we want to paint every cell of the grid with exactly one of the three colors. Here the colors that will be used are Red, Yellow and Green.Now there is a constraint, that is no two adjacent cells have the same color. We have n number of rows of the grid. Finally, we have to find the number of ways we can paint this grid. The answer may be very large so return it modulo 10^9 + 7.So, if the input is like 1, then the output will ... Read More

506 Views
Suppose there is a maze with empty spaces and walls and there is also a ball in that maze. The ball can go through empty spaces by rolling up (u), down (d), left (l) or right (r) directions, but it keeps rolling until hitting a wall. When the ball stops, it could choose the next direction. One hole is also in that maze. The ball will drop into the hole if it rolls on to the hole.So if we have the ball position, the hole position and the maze, we have to find out how the ball could drop into ... Read More

221 Views
Suppose we have a string, s, and we also have a list of words, words present in the array are all of the same length. We have to find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and without any intervening characters.So if the input is like “barfoothefoobarman” and words are [“foo”, “bar”], then the output will be [0, 9]. This is because the substring starting at index 0 and 9 are “barfoo” and “foobar”.To solve this, we will follow these steps −Define a method called ok(), this will take ... Read More