Found 33676 Articles for Programming

Maximum product of indexes of next greater on left and right in C++ Program

sudhir sharma
Updated on 09-Dec-2020 12:13:07

343 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

Maximum product of an increasing subsequence in C++ Program

sudhir sharma
Updated on 09-Dec-2020 12:10:11

191 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

Maximum product of an increasing subsequence of size 3 in C++ program

sudhir sharma
Updated on 09-Dec-2020 12:07:55

179 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

Maximum product of a triplet (subsequence of size 3) in array in C++ Program.

sudhir sharma
Updated on 09-Dec-2020 12:04:27

705 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

How to create three-dimensional arrays of different sizes in R?

Nizamuddin Siddiqui
Updated on 08-Dec-2020 07:22:32

933 Views

A three-dimensional array can have matrices of different size and they are not necessarily to be square or rectangular. Also, all the elements in an array are of same data type. To create a three-dimensional array of different size we would need to use the proper number of rows and columns within the array function.Example Live DemoA1

How to find percentile rank for groups in an R data frame?

Nizamuddin Siddiqui
Updated on 08-Dec-2020 07:18:34

965 Views

The word percentile means the percentage that falls below or above the percentile value. For example, if we have a value that lies at 50th percentile then we would say 50 percent of the values lies below or above that value. The value 50 here is called the percentile rank. To find the percentile rank for groups in an R data frame, we can use mutate function of dplyr package.ExampleConsider the below data frame − Live DemoGroup

How to combine vectors of equal length into a list with corresponding elements representing a single element of the list in R?

Nizamuddin Siddiqui
Updated on 08-Dec-2020 07:14:15

411 Views

To combine three vectors into a list with corresponding elements representing a single element of the list we can use mapply function. For example, if we have three vectors x, y, and z each having number of elements equal to one-hundred then the list with corresponding elements can be created by using mapply(c,x,y,z,SIMPLIFY=FALSE).Example Live Demox1

How to perform tukey HSD in base R?

Nizamuddin Siddiqui
Updated on 08-Dec-2020 07:12:32

900 Views

First thing you must remember while moving on to post hoc analysis is the null hypothesis of the analysis of variance must be rejected, so that we can claim there exists a difference in the group means. Now, once we achieve that the tukey HSD can be performed simply by using TukeyHSD function in base R.ExampleConsider the below data frame − Live Demox1

What is the shortest way to round to the integer value in R?

Nizamuddin Siddiqui
Updated on 08-Dec-2020 07:09:59

132 Views

The shortest way to round to the integer value is using trunc function. The trunc function is used to return the largest integer that is smaller than or equal to the actual value, that means it rounds downs to the nearest integer. It works as a ceiling function for negative number and floor function for positive number.Example Live Demox1

How to create a plot of quadratic regression with fitted values against X in base R?

Nizamuddin Siddiqui
Updated on 08-Dec-2020 07:08:08

219 Views

The quadratic regression model can be plotted by using the plot function but we would need to find the fitted values using the model and this can be done with the help of fitted function. For example, if we have a quadratic model M and the data has an independent variable x then the model against x can be created by using plot(x,fitted(M)).Example Live Demox1

Advertisements