Found 7347 Articles for C++

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

Ayush Gupta
Updated on 09-Sep-2020 07:39:38

58 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 sum of odd number digit sums of all the factors of a number in C++

Ayush Gupta
Updated on 09-Sep-2020 07:42:01

109 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 for number of distinct elements in a subarray | Set 2 in C++

Ayush Gupta
Updated on 09-Sep-2020 07:43:19

308 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 elements in a subarray in C++

Ayush Gupta
Updated on 09-Sep-2020 07:44:10

150 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 frequencies of characters in substrings in C++

Ayush Gupta
Updated on 09-Sep-2020 07:46:24

116 Views

In this problem, we are given a string. And Q queries each has two integers l and r and character ch. our task is to create a program to solve the queries for frequencies of characters in substrings in C++.Problem description: Here for each querry, we will find the frequency of occurrence of the character ‘ch’ in the substring str[l...r].Let’s take an example to understand the problem, Inputstr = “tutorialspoint” Q = 2 0 6 t 5 13 iOutput2 2ExplanationFor query 1 − the substring is “tutoria”, the character t appears 2 times.For query 2 − the substring is “ialspoint”, ... Read More

Queries for decimal values of subarrays of a binary array in C++

Ayush Gupta
Updated on 09-Sep-2020 07:48:03

73 Views

In this problem, we are given a binary array bin[] and Q queries each consists of two values L and R. Our task is to create a program to solve queries for decimal values of subarrays of a binary array in C++.Problem description − Here to solve each query, we will have to find and print the decimal number which is created by the subarray starting from L to R i.e. subarray[L...R].Let’s take an example to understand the problem, Inputbin[] = {1, 1, 0, 0, 1, 0, 1, 0, 0, 0} Q = 2 2 5 0 6Output2 101ExplanationFor query ... Read More

Queries for maximum difference between prime numbers in given ranges in C++

Ayush Gupta
Updated on 09-Sep-2020 07:50:10

338 Views

In this problem, we are given Q queries that consist of two values L and R. Our task is to create a program to solve Queries for maximum difference between prime numbers in given ranges in C++.Problem description: Here, in each querry, we are given two values L and R. We have to find the maximum difference i.e. the difference between the largest and the smallest prime numbers within the given range.Let’s take an example to understand the problem, InputQ = 2 2 45 14 16 41 0OutputExplanationFor query 1, the smallest prime number within the given range is 2 ... Read More

Queries for counts of array elements with values in given range in C++

Ayush Gupta
Updated on 09-Oct-2020 09:21:35

447 Views

In this problem, we are given an array arr[] and Q queries, each can be one of the two types, {1, L, R}− For the count of array elements in the range [L, R].{2, index, val}− For updating the element at index with val.Our task is to create a program to solve the Queries for counts of array elements with values in given range in C++.Let’s take an example to understand the problem, Input:arr[] = {1, 5, 2, 4, 2, 2, 3, 1, 3}Q = 3Query = { {1, 4, 8}, {2, 6, 5}, {1, 1, 4}}Ouput:3 7ExplanationQuery 1: count ... Read More

Queries for counts of multiples in an array in C++

Ayush Gupta
Updated on 09-Oct-2020 09:30:02

261 Views

In this problem, we are given an arr[] and Q queries each consisting of a value m. Our task is to create a program to solve the Queries for counts of multiples in an array in C++.Problem DescriptionFor solving the queries, we need to count all the numbers that are multiples of m. For this we will check for elements divisible by m.Let’s take an example to understand the problem, Input:arr[] = {4, 7, 3, 8, 12, 15}Q = 3 query[] = {2, 3, 5}Ouput:3 3 1ExplanationQuery 1: m = 2, multiples in the array = 4, 8, 12. Count ... Read More

Sum of first N natural numbers which are divisible by 2 and 7 in C++

sudhir sharma
Updated on 05-Aug-2020 08:20:00

110 Views

In this problem, we are given a number N. Our task is to find the sum of first N natural numbers which are divisible by 2 and 7.So, here we will be given a number N, the program will find the sum of numbers between 1 to N that is divisible by 2 and 7.Let’s take an example to understand the problem, Input −N = 10Output −37Explanation −sum = 2 + 4 + 6 + 7 + 8 + 10 = 37So, the basic idea to solve the problem is to find all the numbers that are divisible by 2 ... Read More

Advertisements