Found 33676 Articles for Programming

Count numbers < = N whose difference with the count of primes upto them is > = K in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:53:39

164 Views

Given two integers N and K, the goal is to find the count of numbers such that they follow below conditions −Number=K Where count is the number of prime numbers less than or equal to Number.For ExampleInputN = 5, K = 2OutputCount of numbers < = N whose difference with the count of primes upto them is > = K are: 2ExplanationThe numbers that follow the conditions are: 5 ( 5−2>=2 ) and 4 ( 4−2>=2 )InputN = 10, K = 6OutputCount of numbers < = N whose difference with the count of primes upto them is > = K ... Read More

Count number of ways to partition a set into k subsets in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:50:40

565 Views

Given two numbers e and p. The goal is to count the number of ways in which we can divide e elements of a set into p partitions/subsets.For ExampleInpute=4 p=2OutputCount of number of ways to partition a set into k subsets are: 7ExplanationIf elements are: a b c d then ways to divide them into 2 partitions are: (a, b, c)−(d), (a, b)−(c, d), (a, b, c)−(d), (a)−(b, c, d), (a, c)−(b, d), (a, c, d)−(b), (a, b, d)−(c). Total 7 ways.Inpute=2 p=2OutputCount of number of ways to partition a set into k subsets are: 1ExplanationIf elements are: a b ... Read More

Count number of ways to jump to reach end in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:48:20

345 Views

Given an array of positive numbers. Each element represents the maximum number of jumps that can be made from that index to reach the end of the array. The goal is to find the number of jumps that can be made from that element to reach the end. If arr[] is [ 1, 2, 3 ] then for 1 jumps can be 1, for 2 jumps can be 1 or 2 and for 3 jumps can be made 1, 2 or 3.For ExampleInputarr[] = {1, 2, 3}OutputCount of number of ways to jump to reach end are: 1 1 0ExplanationFor ... Read More

Count number of trailing zeros in Binary representation of a number using Bitset in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:45:13

4K+ Views

Given an integer num as input. The goal is to find the number of trailing zeroes in the binary representation of num using bitset.A bitset stores the bits 0s and 1s in it. It is an array of bits.For ExampleInputnum = 10OutputCount of number of trailing zeros in Binary representation of a number using Bitset are: 1ExplanationThe number 10 in binary is represented as 1010 so trailing zeroes in it is 1.Inputnum = 64OutputCount of number of trailing zeros in Binary representation of a number using Bitset are: 6ExplanationThe number 64 in binary is represented as 10000000 so trailing zeroes ... Read More

Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:42:46

211 Views

Given an integer num as input. The goal is to find the number of trailing zeroes in the product 11 X 22 X 33 X…X numnum.For ExampleInputnum=5OutputCount of number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. are: 5ExplanationThe number of 2s and 5s in the product will be: 11 * 22* 33* 44* 55=11 * 22* 33* (22)4* 55. So total 10 2s and 5 5s, minimum is 5 so trailing zeroes will be 5.Inputnum=10OutputCount of number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. are: 5ExplanationThe number of 2s and 5s in the product will be: 11 *22*33*44*55*66 *77*88*99*1010 = 11 *22*33*44*55*66 *77*88*99*(2*5)10. So ... Read More

Count number of substrings with exactly k distinct characters in C++

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

1K+ Views

Given a string str[] containing lowercase alphabets only and an integer value k. The goal is to find the number of possible substrings of str that have exactly k distinct elements.For ExampleInputstr= ”pqr” k=2OutputCount of number of substrings with exactly k distinct characters are: 2ExplanationThe substrings having exactly 2 distinct elements are: “pq”, “qr”.Inputstr= ”stristr” k=4OutputCount of number of substrings with exactly k distinct characters are: 10ExplanationThe substrings having exactly 2 distinct elements are: “stri”, “tris”, “rist”, “istr”, “stris”, “trist”, “ristr”, “strist”, “tristr”, “stristr”.Approach used in the below program is as follows −In this approach we will an array array[26] ... Read More

Count number of subsets whose median is also present in the same subset in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:37:47

239 Views

Given an array arr[] containing positive numbers. The goal is to find subsets of elements of arr[] such that the median of values of the subset is also present in that set.For ExampleInputarr[] = { 1, 2, 3 }OutputCount of number of subsets whose median is also present in the same subset are: 4ExplanationThe sets with their medians in that same set are: [ 1 ], median is 1 [ 2 ], median is 2 [ 3 ], median is 3 [ 1, 2, 3 ], median is 2Inputarr[] = { 4, 6, 5 }OutputCount of number of subsets whose ... Read More

Count number of subsets of a set with GCD equal to a given number in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:34:41

414 Views

Given an array ar, containing positive numbers and an array GCD[] containing gcd values.The goal is to find the number of subsets of elements of arr[] that have gcd values as given in GCD[].For ExampleInputarr[] = {10, 5, 6, 3}, GCD[] = {2, 3, 5}OutputCount of number of subsets of a set with GCD equal to a given number are: 1 2 2ExplanationThe subsets with GCD equal to 2 is [ 10, 6 ]. Subsets with GCD equal to 3 is [ 3 ], [ 6, 3 ] Subsets with GCD equal to 5 is [ 5 ], [ 10, ... Read More

Count the number of rectangles such that ratio of sides lies in the range [a,b] in C++.

Sunidhi Bansal
Updated on 05-Jan-2021 06:33:03

226 Views

Given sides of rectangles in and range variables first and last. The goal is to find the count of rectangles that have a ratio of their side’s length/breadth lying in the range [ first, last].For ExampleInputrec[] = { { 200, 210 }, { 100, 50 }, { 300, 190}, {180, 200}, {300, 200}} and first = 1.0, last = 1.6OutputCount of number of rectangles such that ratio of sides lies in the range [a, b] are: 4ExplanationThe sides that have ratio in the range [ 1.0, 1.6 ] are : {200, 210}, {300, 190}, {180, 200}, {300, 200}Inputrec[] = { ... Read More

Count the number of sub-arrays such that the average of elements present in the subarray is greater than that not present in the sub-array in C++

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

209 Views

Given an array arr[ ] of positive integers. The goal is to find the count of subarrays of arr[ ] that have an average of its elements greater than the average of the rest of the elements of arr[ ] that are not present in it.For ExampleInputarr[ ] = { 3, 2, 4 }OutputCount of number of sub-arrays such that the average of elements present in the sub−array is greater than that do not present in the sub−array are: 2ExplanationThe subarrays are − [ 3 ], [ 2 ], [ 4 ], [ 3, 2 ], [ 2, 4 ], ... Read More

Advertisements