Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 15 of 44

Queries for number of distinct elements in a subarray in C++

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

In this problem, we are given an array arr[] of size n. And Q queries, each consisting of two elements l and r. Our task is to create a program to solve Queries for number of distinct elements in a subarray in C++.Problem description − Here for each querry, we need to find the total number of distinct integers in the subarray starting from arr[l] to arr[r].Let’s take an example to understand the problem, Inputarr[] = {5, 6, 1, 6, 5, 2, 1} Q = 2 {{1, 4}, {0, 6}}Output3 4ExplanationFor querry 1: l = 1 and r = 4, ...

Read More

Queries for number of distinct elements in a subarray | Set 2 in C++

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

In this problem, we are given an array arr[] of size n and we are given a query. Each query contains two values (L, R). our task is to create a program to solve queries for number of distinct elements in a subarrayProblem description − Here, we will need to find the total number of distinct integers that are present in the subarray from the index (L-1) to (R-1).Let’s take an example to understand the problem, Inputarr[] = {4, 6, 1, 3, 1, 6, 5} query = [1, 4]Output4ExplanationFor query 1: L = 1 & R = 4, we need ...

Read More

Queries for number of distinct integers in Suffix in C++

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

In this problem, we are given an array of N integers. There are Q queries, each containing an integer value m. Our task to create a program to solve Queries for number of distinct integers in Suffix in C++.Problem description − Here, we will need to find the total number of distinct integers that are present in the subarray from the index (m-1) to (N-1). Where m is the value in each query.Let’s take an example to understand the problem −Inputarray = {2, 6, 1, 2, 7, 6} Q = 2 , queries = {1, 5}Output4 2ExplanationFor m = 1, ...

Read More

Queries on sum of odd number digit sums of all the factors of a number in C++

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

In this program, we are given Q queries, each query has a positive integer N. Our task is to create a program to solve queries on sum of odd number digit sums of all the factors of a number in C++.Problem description − To solve each query, we need to find all the factors of the number N. Then add all factors having the digit sum as odd. And return the final sum for each query.Let’s take an example to understand the problem, InputQ = 2, queries = {15, 8}Output8 1ExplanationFor query 1: N = 15, factors of 15 are ...

Read More

Queries on insertion of an element in a Bitonic Sequence in C++

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

In this problem, we are given a bitonic Sequence and Q queries. Each query has an integer x. Our task is to print the length of the bitonic sequence after inserting integers after each query. And at the end print the bitonic sequence.Problem description − Here, we are given a bitonic sequence. And there are Q queries, each containing one integer that is to be added to the sequence. We will add elements from each query to the sequence and then return the length of the bitonic sequence. After all the queries are completed, we will print the bitonic sequence.Bitonic ...

Read More

Queries on count of points lie inside a circle in C++

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

In this problem, we are given n points that lie of a 2D plane, each coordinate is (x, y). Our task is two solve queries. For each query, we are given an integer R. We need to find the count of points lying inside the circle, taking the circle’s center at origin and radius R.Problem descriptionFor each query, we need to find the total number of points out of n points that lie inside the circle (i.e. inside the circumference) of radius R and center point origin (0, 0).Let’s take an example to understand the problem betterInputn = 4 2 ...

Read More

Queries on number of Binary sub-matrices of Given size in C++

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

In this problem, we are given a binary matrix bin[][] of size nXm. Our task is to solve all q queries. For query(x, y), we need to find the number of submatrix of size x*x such that all the elements of array y (binary number).Problem descriptionHere, we need to count the total number of sub-matrix of a given size that consists of only one of the two bits i.e. sub-matrix will all elements 0/1.Let’s take an example to understand the problem, Inputn = 3 , m = 4 bin[][] = {{ 1, 1, 0, 1} { 1, 1, 1, 0} ...

Read More

Maximum sum from a tree with adjacent levels not allowed in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 218 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

Maximum sum from three arrays such that picking elements consecutively from same is not allowed in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 416 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

Maximum sum in a 2 x n grid such that no two elements are adjacent in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 454 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
Showing 141–150 of 433 articles
« Prev 1 13 14 15 16 17 44 Next »
Advertisements