Found 7347 Articles for C++

C++ Program to find the Number of Visible Boxes After Putting One Inside Another

Prateek Jangid
Updated on 25-Nov-2021 07:59:59

261 Views

To solve a problem in which we are given an array containing the size of the boxes. Now we are given a condition that we can fit a smaller box inside a bigger box if the bigger box is at least twice the size of the smaller box. Now we must determine how many visible boxes there are, for example.Input : arr[] = { 1, 3, 4, 5 } Output : 3 Put a box of size 1 in the box of size 3. Input : arr[] = { 4, 2, 1, 8 } Output : 1Approach to Find ... Read More

Find the Number of Subarrays with Odd Sum using C++

Prateek Jangid
Updated on 25-Nov-2021 05:52:19

345 Views

Subarrays are the contiguous part of an array. For example, we consider an array [5, 6, 7, 8], then there are ten non-empty subarrays like (5), (6), (7), (8), (5, 6), (6, 7), (7, 8), (5, 6, 7), (6, 7, 8) and (5, 6, 7, 8).In this guide, we will explain every possible information to find the number of subarrays with odd sums in C++. For finding the number of subarrays with the odd sum, we can use different approaches, so here is a simple example for it −Input : array = {9, 8, 7, 6, 5} Output : 9 ... Read More

Find the Number Of Subarrays Having Sum in a Given Range using C++

Prateek Jangid
Updated on 25-Nov-2021 05:48:46

212 Views

In this article, we will solve the number of subarrays having sum in a given range using the C++ program. We have an array arr[] of positive integers, and a range {L, R} and we have to calculate the total number of subarrays having sum in the given range form L to R. So here is the simple example for the problem −Input : arr[] = {1, 4, 6}, L = 3, R = 8 Output : 3 The subarrays are {1, 4}, {4}, {6}. Input : arr[] = {2, 3, 5, 8}, L = 4, ... Read More

Find the Number of Subarrays with m Odd Numbers using C++

Prateek Jangid
Updated on 25-Nov-2021 05:45:28

185 Views

If you have ever used C ++, you must know what subarrays are and how useful they are. As we know that, in C++, we can solve multiple mathematical problems easily. So in this article, we will explain the complete information on how we can find M odd numbers with the help of these subarrays in C++.In this problem, we need to find many subarrays formed with the given array and integer m where each subarray contains exactly m odd numbers. So here is the simple example of this approach −Input : array = { 6, 3, 5, 8, 9 ... Read More

Find the Number of Subarrays whose Minimum and Maximum are Same using C++

Prateek Jangid
Updated on 25-Nov-2021 05:37:46

419 Views

In this article, we will solve the problem of finding the number of subarrays whose maximum and minimum elements are the same using C++. Here is the example for the problem −Input : array = { 2, 3, 6, 6, 2, 4, 4, 4 } Output : 12 Explanation : {2}, {3}, {6}, {6}, {2}, {4}, {4}, {4}, {6, 6}, {4, 4}, {4, 4} and { 4, 4, 4 } are the subarrays which can be formed with maximum and minimum element same. Input : array = { 3, 3, 1, 5, 1, 2, 2 } Output : 9 ... Read More

Find the Number of subarrays having sum of the form k^m, m >= 0 using C++

Prateek Jangid
Updated on 25-Nov-2021 05:32:32

82 Views

In this article, we will explain everything about solving the number of subarrays having the sum of the form k^m, m >= 0 in C++. Given an array arr[] and an integer K, we need to find the number of subarrays having sum in the form of K^m where m is greater than equal to zero, or we can say we need to find the number of subarrays having sum equal to some non-negative power of K.Input: arr[] = { 2, 2, 2, 2 } K = 2 Output: 8 Sub-arrays with below indexes are valid: [1, 1], ... Read More

Find the Number of subarrays having sum less than K using C++

Prateek Jangid
Updated on 24-Nov-2021 12:39:29

882 Views

In this article, we will find out the number of subarrays having a sum less than K using C++. In this problem, we have an array arr[] and an integer K. So now we have to find subarrays that have a sum less than K. Here is the example −Input : arr[] = {1, 11, 2, 3, 15} K = 10 Output : 4 {1}, {2}, {3} and {2, 3}Approach to Find SolutionNow we will use two different methods to solve the given problem −Brute ForceIn this approach, we will iterate through all the subarrays and calculate their sum and ... Read More

Find the Number Of Subarrays Having Sum in a Given Range in C++

Prateek Jangid
Updated on 24-Nov-2021 12:35:40

767 Views

In this article, we will solve the number of subarrays having sum in a given range using the C++ program. We have an array arr[] of positive integers, and a range {L, R} and we have to calculate the total number of subarrays having sum in the given range form L to R. So here is the simple example for the problem −Input : arr[] = {1, 4, 6}, L = 3, R = 8 Output : 3 The subarrays are {1, 4}, {4}, {6}. Input : arr[] = {2, 3, 5, 8}, L = 4, ... Read More

Find the number of subarrays have bitwise OR >= K using C++

Prateek Jangid
Updated on 24-Nov-2021 12:26:43

719 Views

In this article, we will provide a brief explanation on solving the number of subarrays that have bitwise OR>=K in C++. So we have an array arr[] and an integer K, and we have to find the number of subarrays that have OR(bitwise or) greater than or equal to K. So here is the example of the given problem −Input: arr[] = {1, 2, 3} K = 3 Output: 4 Bitwise OR of sub-arrays: {1} = 1 {1, 2} = 3 {1, 2, 3} = 3 {2} = 2 {2, 3} = 3 {3} = 3 4 sub-arrays have ... Read More

Find the Number of Stopping Stations using C++

Prateek Jangid
Updated on 24-Nov-2021 12:22:19

130 Views

There are n number of intermediate train stations between point X and Y. Count the number of different ways trains can be arranged to stop at s stations such that no two stations are next to each other. So in this article, we will explain every possible approach to find out the number of stopping stations. Looking at the problem, we can find that we need to find combinations by which trains can be stopped at s number of stations.Approaches to Solve the ProblemLet's take an example that there are eight intermediate stations and we need to find the ways ... Read More

Advertisements