Sunidhi Bansal has Published 1085 Articles

Count number of trees in a forest in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 05-Jan-2021 13:27:47

499 Views

Given vertices of a forest ( collection of trees). The goal is to find the number of trees in that forest. We will do this by running a DFS (depth first search) algorithm on the forest.For ExampleInputedges = { { 1, 3 }, {2, 8}, {2, 6}, {3, 5}, {3, ... Read More

Construct sum-array with sum of elements in given range in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 05-Jan-2021 07:30:09

588 Views

Given an array arr[ ] containing integers only and an odd number sum. The goal is to create a sum array arr_2[ ] such each arr_2[i] is the sum of previous sum/2 elements of arr[] + arr[i] + next sum/2 elements of arr[]. If sum is 1 then arr_2[i]=arr[i]For ExampleInputarr[] ... Read More

Count the number of currency notes needed in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 05-Jan-2021 07:28:24

689 Views

Given an amount in rupees that one has to pay, say pay_rupees and an unlimited amount of banknotes that have value as Rupees_amount_1 and Rupees_amount_2. The goal is to pay pay_rupees using exactly the total number of notes=distribution_total and count the number of type Rupees_amount_1 notes required. If there is ... Read More

Count number of strings (made of R, G and B) using given combination in C++

Sunidhi Bansal

Sunidhi Bansal

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

378 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 ... Read More

Count number of subsets having a particular XOR value in C++

Sunidhi Bansal

Sunidhi Bansal

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

412 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 ... Read More

Count the number of non-increasing subarrays in C++

Sunidhi Bansal

Sunidhi Bansal

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

386 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 ... Read More

Count the number of holes in an integer in C++

Sunidhi Bansal

Sunidhi Bansal

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

525 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 ... Read More

Count the number of intervals in which a given value lies in C++

Sunidhi Bansal

Sunidhi Bansal

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

416 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 ... Read More

Count of Binary Digit numbers smaller than N in C++

Sunidhi Bansal

Sunidhi Bansal

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

282 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 ... Read More

Count of arrays in which all adjacent elements are such that one of them divide the another in C++

Sunidhi Bansal

Sunidhi Bansal

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

412 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 ... Read More

Advertisements