Sunidhi Bansal has Published 1085 Articles

Count number of trailing zeros in product of array in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:33:04

380 Views

We are given an array Arr[] of positive integers of size N. The goal is to count the number of trailing zeroes present in the product of all elements of the array.We will do this by counting the factors of each number. We will count 2 and 5 as factors ... Read More

Count number of ways to divide a number in parts in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:31:15

447 Views

We are given a positive number N. The goal is to count the number of ways in which the number N can be divided into 3 parts. The parts may or may not be equal. N lies in range [1, 5000].We will do this by using three for loops for ... Read More

Count numbers whose XOR with N is equal to OR with N in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:30:18

124 Views

We are a number N. The goal is to find numbers between 0 and N whose OR with N is equal to XOR with N.We will do this by traversing no. from i=0 to i

Count numbers whose difference with N is equal to XOR with N in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:28:03

132 Views

We are a number N. The goal is to find numbers between 0 and N whose difference with N is equal to XOR with N.We will do this by traversing no. from i=0 to i

Count numbers whose sum with x is equal to XOR with x in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:26:37

196 Views

We are a number X. The goal is to find numbers between 0 and X whose sum with X is equal to XOR with X.We will do this by traversing no. from i=0 to i

Count pieces of the circle after N cuts in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:25:05

125 Views

We are given an integer N which represents the number of cuts applied on a 2D-circle. Each circle divides the circle in two halves. Goal is to find the pieces of the circle after N cuts.Number of pieces= 2 * no. of cutsLet’s understand with examples.Input − N=1Output − Pieces ... Read More

Count quadruples from four sorted arrays whose sum is equal to a given value x in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:23:14

203 Views

We are given four arrays A[], B[], C[] and D[]. The goal is to find all quadruples of elements of these arrays such that A[i]+B[j]+C[k]+D[l] =x. All four arrays have the same number of elements N.We will do this by traversing each array once and compare if A[i]+B[j]+C[j]+D[l]==x. If true ... Read More

Count Primes in Ranges in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:21:03

8K+ Views

We are given range variables START and END. The goal is to find the count of prime numbers in the range [START, END].We will check if number i in range is prime by checking if any number other than 1 fully divides it and is between 1 and i/2. If ... Read More

Count strings that end with the given pattern in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:19:13

182 Views

We are given an array of strings str[] and a pattern string pat. The goal is to find the string elements of str[] that have pattern pat at the end.We will traverse each string of str and compare last characters with pat. If they match incrementLet’s understand with examples.Input str[]={ “kittens”, ... Read More

Count square and non-square numbers before n in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Oct-2020 05:17:02

976 Views

We are given a number N. The goal is to find ordered pairs of positive numbers such that the sum of their cubes is N.Naive ApproachTraverse all numbers from 1 to N and check if it is a perfect square. If floor(sqrt(i))==ceil(sqrt(i)).Then the number is a perfect square.Efficient ApproachPerfect squares ... Read More

Advertisements