Sunidhi Bansal has Published 1085 Articles

Count of only repeated element in a sorted array of consecutive elements in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Aug-2020 08:21:18

5K+ Views

We are given an array of consecutive numbers of length n. The array has only one number which is repeated more than once. The goal is to get the number of times that element is repeated in the array. Or we can say find the length of a repeated element ... Read More

Count numbers upto N which are both perfect square and perfect cube in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Aug-2020 08:19:15

5K+ Views

We are given a number N. The goal is to count the numbers upto N that are perfect squares as well as perfect cubes. For example, 1, 64 are both perfect squares and perfect cubes.We will use sqrt() to calculate square root and cbrt() to calculate cube root of a ... Read More

Count numbers with unit digit k in given range in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 31-Aug-2020 08:16:53

551 Views

We are given an interval [first, last]. The goal is to find the count of numbers that have a unit digit k and lie between range [first, last].We will do this by traversing from i=first to i=last. For each number i compare its unit digit with the k, if they ... Read More

Count of m digit integers that are divisible by an integer n in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 12:05:47

277 Views

We are given two integers m and n. The goal is to count m digit numbers that are divisible by n.If m=1, then numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and n=3 then numbers divisible by 3=0, 3, 6, 9 count=4.Let’s understand with examples.Input − ... Read More

Count number of pairs (i, j) such that arr[i] * arr[j] > arr[i] + arr[j] in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 12:03:46

705 Views

We are given an array of n positive numbers.The goal is to count the ordered pairs (i,j) such that arr[i]*arr[j] > arr[i]+arr[j] and 0sum.Traverse array using two for loops for each element of the pair.Outer Loop from 0

Count number of ordered pairs with Even and Odd Sums in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 12:01:45

366 Views

We are given an array of n positive numbers.The goal is to count the ordered pairs (arr[x], arr[y]) with the sum of arr[x] and arr[y] is even or odd. Pair ( arr[i], arr[j] ) and ( arr[j], arr[i] are counted as separate.We will traverse the array using two for loops ... Read More

Count number of ordered pairs with Even and Odd Product in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 11:59:47

214 Views

We are given an array of n positive numbers.The goal is to count the ordered pairs (arr[x], arr[y]) with the product of arr[x] and arr[y] is even or odd. Pair ( arr[i], arr[j] ) and ( arr[j], arr[i] are counted as separate.We will traverse the array using two for loops ... Read More

Count numbers with same first and last digits in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 11:57:28

478 Views

We are given an interval [first, last]. The goal is to find the count of numbers that have the same first and last digit within this interval. For example, 232 has the same first and last digit as 2.We will do this by traversing from i=first to i=last. For each ... Read More

Count the number of operations required to reduce the given number in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 11:53:16

309 Views

We are given with a positive integer K and an array Ops[] which contains integers. The goal is to find the number of operations required to reduce K such that it becomes less than 0. Operations are −First operation is K + Ops[0], first element added to KAfter 1. Add ... Read More

Count the number of pairs that have column sum greater than row sum in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 29-Aug-2020 11:51:02

179 Views

We are given a matrix of size NXN. The goal is to find the count of all valid pairs of indexes (i, j) such that the sum elements of column j is greater than the sum of elements of row i.We will do this by traversing the matrix and calculate ... Read More

Advertisements