Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Articles
Page 38 of 597
Eulerian Number in C++
In mathematics, the Eulerian number is a special type of combination number. It defines the number of permutations in which the next element is a specific number greater than the previous one.Denoted as, A(n, m) is permutation from 1 to n in which two numbers vary by m.Problem Statement: In this problem, we are given two numbers m and n. And we need to find the number of permutations that are the Eulerian Number.Let’s take an example to understand the problem, Input: n = 4, m = 2Output: 11Explanation: All permutations of number from 1 to 4 are −1 2 3 4 ...
Read MoreMaximum product of a triplet (subsequence of size 3) in array in C++ Program.
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 MoreMaximum product of an increasing subsequence of size 3 in C++ program
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, #include using namespace std; ...
Read MoreMaximum product of an increasing subsequence in C++ Program
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 MoreEvaluate a boolean expression represented as string in C++
In this problem, we are given a string exp that represents a boolean expression. Our task is to evaluate the boolean expression represented as String.The valid characters in the expression are −0 or 1 denoting the boolean value& denoting AND operation| denoting OR operation^ denoting XOR operationWe need to solve this expression and return the result.Let's take an example to understand the problem, Input: str = 1&1|0^1^0&1Output: 0Explanation: 1&1|0^1^0&11 AND 1 OR 0 XOR 1 XOR 0 AND 11 OR 0 XOR 1 XOR 0 AND 11 XOR 1 XOR 0 AND 10 XOR 0 AND 10 AND 10Solution Approach:A simple solution is ...
Read MoreMaximum product of indexes of next greater on left and right in C++ Program
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 MoreEvaluate an array expression with numbers, + and - in C++
In this problem, we are given an array arr[] consisting of n character values denoting an expression. Our task is to evaluate an array expression with numbers, + and –. The expression consists of only, numbers, ‘+’ character and ‘- ’ character.Let’s take an example to understand the problem, Input: arr = {“5”, “+”, “2”, “-8”, “+”, “9”, }Output: 8Explanation: The expression is 5 + 2 - 8 + 9 = 8Solution Approach:The solution to the problem is found by performing each operation and then returning the value. Each number needs to be converted to its equivalent integer value.Program to illustrate the working of ...
Read MoreMaximum product subset of an array in C++ program
In the problem, we are given an array arr[] of n integer values. Our task is to create a program to find the Maximum product subset of an array.Problem Description − Here, we need to calculate the maximum possible product of a subset of elements of an array.Subset − An array sub[] is a subset of array arr[] if all elements of sub[] are present in arr[].Let’s take an example to understand the problem, Inputarr[] = {4, 5, 2, −1, 3}Output40ExplanationSubset sub[] = {4, 5, 2} Prod = 4*5*2 = 40Solution ApproachA simple and easy approach to solve the problem ...
Read MoreEvaluation of Risk in Investments in C++
In this problem, we are given two arrays each denoting an investment plan. Our task is to perform the evaluation of Risk in Investment and find which of the two investments is more promising.Both the investments I1[][] and I2[][] has a set of outcomes and the probability of that investment outcome.Using these values, we need to find the risk in each investment and then print the better investment out of the two investments.For this, we will be using statistical mathematics and find some values that will help us conclude to the better investment.We will find these values, Mean or average amount ...
Read MoreMaximum size of sub-array that satisfies the given condition in C++ program
In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the maximum size of sub-array that satisfies the given condition.Problem Description − We need to find the length of largest subarray that satisfies any one of the below condition, arr[k] > arr[k+1], if k is odd and arr[k] < arr[k+1], if k is even. For all elements of the subarray.arr[k] < arr[k+1], if k is odd and arr[k] > arr[k+1], if k is even. For all elements of the subarray.Here, k is the index of the element of the ...
Read More