Count Number of Strings Made of R, G and B Using Given Combination in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:26:32

393 Views

Given three numbers R, G and B and letters ‘R’, ‘G’ and ‘B’ only. The goal is to find the count of possible strings that can be made using at least R Rs, at least G Gs and at least B Bs in it. The numbers R, G and B have sum less than or equal to the length of strings possible.For ExampleInputR = 1, G = 1, B = 1 length=3OutputCount of number of strings (made of R, G and B) using given combination are − 6ExplanationThe possible strings will be : “RGB”, “RBG”, “BRG”, “BGR”, “GRB”, “GBR”. That ... Read More

Count Number of Subsets Having a Particular XOR Value in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:25:01

424 Views

Given an array arr[ ] containing positive integers and a value match. The goal is to find the subsets of arr[] that contain elements that have XOR = match.For ExampleInputarr[] = {4, 2, 8, 10} match=12OutputCount of number of subsets having a particular XOR value are: 2ExplanationSubsets of arr with XOR of elements as 0 are − [ 4, 8 ], [4, 2, 10]Inputarr[] = {3, 5, 2, 7} match=5OutputCount of number of subsets having a particular XOR value are− 2Explanationubsets of arr with XOR of elements as 0 are− [ 5 ], [2, 7]Approach used in the below program ... Read More

Count the Number of Non-Increasing Subarrays in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:20:43

399 Views

Given an array arr[] containing positive integers. The goal is to find the number of subarrays of length at least 1 which are non−increasing. If arr[]= {1, 3, 2}, then subarrays will be {1}, {2}, {3}, {3, 2}. Count is 4.For ExampleInputarr[] = {5, 4, 5}OutputCount of number of non-increasing subarrays are: 7ExplanationThe subarrays will be − {5}, {4}, {5}, {5, 4}Inputarr[] = {10, 9, 8, 7}OutputCount of number of non−increasing subarrays are − 10ExplanationThe subarrays will be − {10}, {9}, {8}, {7}, {10, 9}, {9, 8}, {8, 7}, {10, 9, 8}, {9, 8, 7}, {10, 9, 8, 7}Approach used ... Read More

Count the Number of Holes in an Integer in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:19:18

540 Views

Given an array of holes[10] containing a number of holes in numbers 0 to 9. The goal is to find the number of holes in an integer number given as input. Given − holes[] = { 2, 1, 1, 0, 0, 1, 1, 1, 0 }For ExampleInputnumber = 239143OutputCount the number of holes in an integer are: 3ExplanationWe will count holes given in holes[] 239143 ( 1+0+0+2+0+0 )Inputnumber = 12345OutputCount the number of holes in an integer are: 3ExplanationWe will count holes given in holes[] 12345 ( 1+1+0+0+1)Approach used in the below program is as follows −Simply take each leftmost ... Read More

Count Intervals for a Given Value in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:17:30

432 Views

Given a 2D array arr[][] containing intervals and a number ‘value’. The goal is to find the number of intervals present in arr between which value lies. For example intervals are [ [1, 5], [3, 7] ] and value=4 then it lies in both these intervals and count would be 2.For ExampleInputarr[4][2] = { { 1, 20 }, { 12, 25 }, { 32, 40 }, { 15, 18 } } value=16OutputCount of number of intervals in which a given value lies are: 3ExplanationThe value 16 lies between 1−20, 12−25 and 15−18Inputarr[4][2] = {{ 1, 20 }, { 20, 30 ... Read More

Count of Binary Digit Numbers Smaller than n in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:15:24

294 Views

Given an integer N as input. The goal is to find the count of integers that are less than N and represented in Binary form. For example if input N is 12 then numbers less than 12 are 1, 10, 11 that are binary and contain 0s and 1s as digits. The answer would be 3.For ExampleInputN=100OutputCount of Binary Digit numbers smaller than N are − 4ExplanationThe Binary numbers less than 100 are − 1, 10, 11, 100InputN=120OutputCount of Binary Digit numbers smaller than N are: 7ExplanationThe Binary numbers less than 100 are : 1, 10, 11, 100, 101, 110, ... Read More

Count of Arrays Where Adjacent Elements Divide Each Other in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:12:32

422 Views

Given two integers named ‘one’ and ‘another’. The goal is to find the number of possible arrays such that −The elements in the array are in range between 1 and ‘another’.All elements of array are such that arr[i] divides arr[i+1] or arr[i+1] divides arr[i+2]....and so on.The length of the array is ‘one’.For ExampleInputone = 3, another = 2OutputCount of arrays in which all adjacent elements are such that one of them divide the another are: 8ExplanationThe arrays will be: [ 1, 1, 1 ], [ 1, 1, 2 ], [ 1, 2, 1 ], [ 1, 2, 2 ], [ ... Read More

Count of All N-Digit Numbers Such That Num Plus Rev Num Equals 10^N - 1 in C++

Sunidhi Bansal
Updated on 05-Jan-2021 07:08:44

156 Views

Given a number N as input. The goal is to find the count of all N digit numbers that have sum Count of all N digit numbers such that num + Rev(num) = 10N − 1num+rev(num)=10N−1For ExampleInputN=4OutputCount of all N digit numbers such that num + Rev(num) = 10N − 1 are − 90ExplanationThe numbers would be − 1. 1188 + 8811 = 9999 2. 2277 + 7722 = 9999 3. 1278 + 8721 = 9999 ……...total 90 numbersInputN=5OutputCount of all N digit numbers such that num + Rev(num) = 10N − 1 are − 0ExplanationAs N is odd, ... Read More

Count of All Possible Values of x Such That a < x < b in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:58:56

241 Views

Given two integers A and B and a number X. The goal is to find the count of values that X can have so that A%X=B. For the above equation if, A==B then infinite values of X are possible, so return −1. If A < B then there would be no solution so return 0. If A>B then return count of divisors of (AB) as result.For ExampleInputA=5, B=2OutputCount of all possible values of X such that A % X = B are: 1Explanation5%3=2. So X is 3 here.InputA=10, B=10OutputCount of all possible values of X such that A % X ... Read More

Count Number of Pop Operations on Stack in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:57:21

715 Views

Given an array of numbers and a stack. All the elements of the array are present inside the stack The goal is to find the count of pop operations required for getting individual array elements.The stack is filled in decreasing order, the first element is highest and top element is lowest.For ExampleInputStack [ 7, 6, 2, 1 ] array : 2, 1, 6, 7OutputCount of number of pop operations on stack to get each element of the array are: 3 1 0 0ExplanationTraversing array from 0th index, To get 2 we will pop stack three times. So arr[0] is 3. ... Read More

Advertisements