- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7347 Articles for C++
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
278 Views
In this problem, we are given an array arr[]. Our task is to create a program to calculate the Maximum product of indexes of next greater on left and right.Problem Description −For the given array we need to find the product of maximum value of left[i]*right[i]. Both arrays are defined as −left[i] = j, such that arr[i] j. right[i] = j, such that arr[i] < arr[j] and i < j. *The array is 1 indexed.Let’s take an example to understand the problem, Inputarr[6] = {5, 2, 3, 1, 8, 6}Output15ExplanationCreating left array, left[] = {0, 1, 1, 3, 0, ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
125 Views
In this problem, we are given an array arr[] of size n. Our task is to find the maximum product of an increasing subsequence.Problem Description − We need to find the maximum product of increasing subsequence of any size possible from the elements of the array.Let’s take an example to understand the problem, Inputarr[] = {5, 4, 6, 8, 7, 9}Output2160ExplanationAll Increasing subsequence: {5, 6, 8, 9}. Prod = 2160 {5, 6, 7, 9}. Prod = 1890 Here, we have considered only max size subsequence.Solution ApproachA simple solution to the problem is by using a dynamic programming approach. For this, ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
102 Views
In this problem, we are given an array arr[] of n positive integers. Our task is to create a program to find the Maximum product of an increasing subsequence of size 3.Problem Description − Here, we need to find the maximum product of 3 elements of the array such that they form an increasing subsequence and array index are also increasing i.e.arr[i]*arr[j]*arr[k] is maximum, arr[i] j to n−1Step 1.1.1.1 −if(arr[j] < arr[k]) −> find prod = arr[i]*arr[j]*arr[k].Step 1.1.1.2 −if(maxProd > prod) −> maxProd = prod.Step 2 −Return maxProd.ExampleProgram to illustrate the working of our solution, Live Demo#include using namespace ... Read More
![sudhir sharma](https://www.tutorialspoint.com/assets/profiles/125719/profile/60_65058-1565947418.jpg)
400 Views
In this problem, we are given an array arr[] consisting of n integers. Our task is to find the maximum product of a triplet (subsequence of size 3) in array. Here, we will be finding the triple with maximum product value and then return the product.Let’s take an example to understand the problem, Inputarr[] = {9, 5, 2, 11, 7, 4}Output693ExplanationHere, we will find the triplet that gives the maximum product of all elements of the array. maxProd = 9 * 11 * 7 = 693Solution ApproachThere can be multiple solutions to the problem. We will be discussing them here, ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
72 Views
We are an equilateral triangle with side length. The goal is to count the number of distinct rectangles that can be present inside the triangle such that horizontal sides of the rectangle are parallel to the base. Also all end points of the rectangle touch the dots as shown.Let us understand with examplesInput − sides=3Output − Count of distinct rectangles inscribed in an equilateral triangle are − 1Explanation − The figure above shows the rectangle.Input − sides=10Output − Count of distinct rectangles inscribed in an equilateral triangle are − 200Approach used in the below program is as followsAs from the ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
816 Views
We are given a num number as input. The goal is to count the number of possible strings of length num such that all adjacent characters have difference between ascii values as 1.If num is 2 then strings will be “ab”, “ba”, “bc”, “cb”, ……..”yz”, “zy”.Let us understand with examplesInput − num=3Output − Count of strings where adjacent characters are of difference one are − 98Explanation − Some sample strings are: “abc”, “aba”, “cde” …..”xyx”, “zyz”, “xyz”.Input − num=2Output − Count of strings where adjacent characters are of difference one are − 50Explanation − Some sample strings are: “ab”, “ba”, ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
80 Views
We are given a number num as input. The goal is to find the number of pairs of form (i, j) such that ((num%i)%j)%num is maximized and i and j both are in range [1, num].Let us understand with examplesInput − num=4Output − Count of pairs of (i, j) such that ((n % i) % j) % n is maximized are − 3Explanation − Pairs will be: (3, 2), (3, 3), (3, 4)Input − num=6Output − Count of pairs of (i, j) such that ((n % i) % j) % n is maximized are − 4Explanation − Pairs will be: ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
115 Views
We are given a string str containing 0s, 1s and other alphabets . It also contains patterns of the form “1(0+)1” where 0+ means any number (>0) of consecutive 0s. The goal is to find such patterns ( “1(0+)1” ) inside string str.Let us understand with examplesInput − str = “abb010bb10111011”Output − Count of occurrences of a “1(0+)1” pattern in a string are − 2Explanation − The patterns inside str are highlighted: “abb010bb10111011”, “abb010bb10111011”Input − str = “01001011001001100”Output − Count of occurrences of a “1(0+)1” pattern in a string are − 4Explanation − The patterns inside str are highlighted: “01001011001001100”, ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
94 Views
We are given a circle with K equidistant points on its circumference. Also we are given two points A and B. The goal is to count the number of triangles possible using these points such that they have an obtuse angle ACB( angle greater than 90o) inside them. The points A and B are such that A < B.Here K=8, A=2, B=5, count of points=2 (C, C’) such that angle LACB, LAC’B are obtuse.Let us understand with examplesInput − k=10, A=2, B=4Output − Count of obtuse angles in a circle with ‘k' equidistant points between 2 given points are − ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
64 Views
We are given a number N and another number L. The goal is to find the numbers between 1 and N that have a difference between the number itself and the sum of its digits is not less than L.If N=23, L=10 then the count of such numbers will be 4.23-(2+3)=18, 22-(2+2)=18, 21-(2+1)=18, 20-(2+0)=18.All above numbers meet the conditionBut 19-(1+9)=9 which is less than L, similarly 18, 17….1.Let us understand with examplesInput − N=30 L=19Output − Count of Numbers such that difference between the number and sum of its digits not less than L are − 1Explanation − Only 30 ... Read More