Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 19 of 44

Maximum product of subsequence of size k in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 586 Views

In this problem, we are given an array arr[] of integers and a number k. Our task is to create a program to find the Maximum product of subsequence of size k in C++.Problem Description − Here, we need to find the subsequence of size k, 1

Read More

Maximum product of two non-intersecting paths in a tree in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 373 Views

In this problem, we are given an undirected connected tree T with n nodes. Our task is to create a program to find the Maximum product of two nonintersecting paths in a tree in C++.Problem Description − To find the maximum product of two nonintersecting paths in a tree. We will find all the non-interesting paths and then find the product of their lengths.Let’s take an example to understand the problem, InputGraph −Output8ExplanationThe non-intersecting paths that are considered are C-A-B and F-E-D-G-H.The lengths are 2 and 4. Product = 8.Solution ApproachThe solution to this problem is by traversing the tree ...

Read More

Program to find the Circumcircle of any regular polygon in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 242 Views

In this problem, we are given two numbers that give the number of sides of a polygon N and the length of each side A. Our task is to create a Program to find the Circumcircle of any regular polygon in C++.Problem description − Here, we need to find the radius and area of the circumcircle of the regular polygon whose side number and length are given.Let’s take an example to understand the problem, Inputn = 4 a = 2Program to illustrate the working of our solution, Example#include using namespace std; void CalcRadAreaCircumcircle(float n, float a) {    float ...

Read More

Maximum product quadruple (sub-sequence of size 4) in array in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 453 Views

In this problem, we are given an array arr[]. Our task is to create a program to find the Maximum product quadruple (sub-sequence of size 4) in array in C++.Code description − Here, we need to find a quadruple (sub-sequence of size 4) such that the product of all elements is maximum.Let’s take an example to understand the problem, Inputarr[] = {4, -2, 5, -6, 8}Output840ExplanationThe quadruple, (-3, 5, -7, 8) with product 840.Solution ApproachThere can be multiple solutions to a given problem.One simple solution is using the direct method by traversing the array. Then finding all possible quadruples in ...

Read More

Program to find the diameter, cycles and edges of a Wheel Graph in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 428 Views

In this problem, we are given a number that denotes the number of vertices of a Wheel Graph. Our task is to create a Program to find the diameter, cycles and edges of a Wheel Graph in C++.Problem description − Here, we need to find the number of cycles, number of edges, and the diameter of Wheel Graph with n vertices.First, let’s understand some basics about Wheel Graph −A wheel graph is obtained from a cycle graph Cn-1 by adding a new vertex. That new vertex is called a Hub which is connected to all the vertices of Cn.Example of ...

Read More

Maximum Product Subarray - Using Two Traversals in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 247 Views

In this problem, we are given an array arr[] of integers. Our task is to create a program to find the Maximum Product Subarray - Using Two Traversals in C++.Problem description − Here in the array, we will find the maximum product subarray using two traversals one from index 0 and another index (n-1).Let’s take an example to understand the problem, Inputarr[] = {4, -2, 5, -6, 0, 8}Output240ExampleSubarray = {4, -2, 5, -6} Maximum product = 4 * (-2) * 5 * (-6) = 240Solution ApproachTo solve this problem using two traversals. Here, we will find the maximum product ...

Read More

Maximum Product Subarray | Added negative product case in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 251 Views

In this problem, we are given an array of integers(positive as well as negative). Our task is to create a program to calculate the Maximum Product Subarray in C++.Problem Solution − Here, we have an array that contains positive, negative, and zero numbers. We need to find the product of subarrays created by elements of the array. And maximize the product of the subarray.Let’s take an example to understand the problem, Inputarr[] = {-1, 2, -7, -5, 12, 6}Output5040ExplanationThe subarray with the maximum product is {2, -7, -5, 12, 6}Product = 5040Solution ApproachTo solve this problem, we are given an ...

Read More

Program to find the Discount Percentage in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given two numbers that define the marked price(M) and selling price(S) of a certain product. Our task is to create a program to find the Discount Percentage in C++.Discount is the amount that is deducted from the actual price (marked price) on a product.The formula for discount is, discount = marked price - selling priceDiscount percentage is the percentage of the price that is deducted from the actual price of the product.The formula for discount percentage is, discount percentage = (discount / marked price ) * 100Let’s take an example to understand the problem, Input240, ...

Read More

Maximum product subset of an array in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 252 Views

In this tutorial, we will be discussing a program to find maximum product subset of an array.For this we will be provided with an array containing positive and negative values. Our task is to find the maximum product for a subset of the array.Example#include using namespace std; int maxProductSubset(int a[], int n) {    if (n == 1)       return a[0];       int max_neg = INT_MIN;       int count_neg = 0, count_zero = 0;       int prod = 1;    for (int i = 0; i < n; i++) {   ...

Read More

Maximum profit after buying and selling the stocks in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 916 Views

In this problem, we are given an array stkprice[] that denotes the price of a certain stock on i-th day. Our task is to create a program to calculate Maximum profit after buying and selling the stocks in C++.Problem Description − Here, we need to check when can be bought and sell the stock to gain profit. To gain profit, we need to buy the stock at a low price and sell it when the price goes up. And repeat the same when the drop is encountered again.Let’s take an example to understand the problem, Inputstkprice[] = {120, 310, 405, ...

Read More
Showing 181–190 of 433 articles
« Prev 1 17 18 19 20 21 44 Next »
Advertisements