Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 35 of 81

Count pairs from two linked lists whose product is equal to a given value in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 159 Views

We are given with two linked lists and the task is to form the pairs using the integer elements of linked lists such that their product is equal to a given value which is let’s say, k. A linked list is a sequence of data structures, which are connected together via links.Input vector v_1 = {5, 7, 8, 10, 11}, . vector v_2 = {6, 4, 3, 2, 0} , int k = 20Output Count of pairs from two linked lists whose product is equal to a given value k are: 2Explanation The pairs which can be formed using the given linked lists ...

Read More

Count of elements of an array present in every row of NxM matrix in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 892 Views

We are given an array of integer type elements and a matrix or 2-D array of given row and column size and the task is to calculate the count of elements of an array that are present in each row of a matrix.Input int arr = { 2, 4, 6} and int matrix[row][col] = { { 2, 4, 6 }, {3, 4, 6}, {6, 2, 1}}Output Elements of array in row 1 are: 3 Elements of array in row 2 are: 2 Elements of array in row 3 are: 2Explanation we are having array containing 2, 4 and 6 as elements and now ...

Read More

Count of matrices (of different orders) with given number of elements in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 331 Views

We are given the total number of elements and the task is to calculate the total number of matrices with different orders that can be formed with the given data. A matrix has an order mxn where m are the number of rows and n are the number of columns.Input − int numbers = 6Output −Count of matrices of different orders that can be formed with the given number of elements are: 4Explanation − we are given with the total number of elements that a matrix of any order can contain which is 6. So the possible matrix order with ...

Read More

Count of numbers having only 1 set bit in the range [0, n] in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 301 Views

We are given a number and the task is to calculate the count of numbers from the range 0 till the given number let’s say, num having exactly one set bitSet bits in a binary number is represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as set bit in the terms of the computer.Input − int num = 15Output − Count of numbers having only 1 set bit in the range [0, 15] are − 4Explanation − The ...

Read More

Count the number of elements in an array which are divisible by k in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

We are given with an array of positive integer numbers and an integer variable k. The task is to calculate the count of the number of elements in an array which is divisible by the given value k.Input − int arr[] = {4, 2, 6, 1, 3, 8, 10, 9}, k = 2Output − Count the number of elements in an array which are divisible by 2 are − 5Explanation − we will divide the elements in an array by a value k and check whether the reminder is 0 or not. So, 4 is divisible by 2, 2 is ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 6K+ 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 in the array.We will traverse the array from i=0 to i

Read More

Count of numbers which can be made power of 2 by given operation in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 436 Views

We are given an array of positive integers. The goal is to find the count of numbers that can be made power of two by adding 1 to them utmost once.We will check using log2(i) that number is power of two or can become power of two by adding 1 to it. If yes increment count.Let’s understand with examples.Input − arr[]= {1, 3, 2, 5, 6 }, Output − Count of numbers that can become power of 2: 3Explanation − 1+1=2 → 21 , 3+1=4 → 22 , 2=21 others will become 5+1=6, 6+1=7Input − arr[]= {2, 4, 8, 16 ...

Read More

Count of elements whose absolute difference with the sum of all the other elements is greater than k in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 303 Views

We are given an array of integers. The goal is to count numbers such that the absolute difference between the sum of all elements and that element is greater than variable k.We will do this by getting the sum of elements of the array. Now for each element arr[i], check if −sum-2(arr[i])>k, as sum already includes arr[i] so subtract it twice. If true increment count.Let’s understand with examples.Input − arr[]= { 1, 2, 3, 0, 3, 2, 0, 1 }, k=10Output − Count of elements: 2Explanation − Sum of elements is 1212-1-1=10, 12-2-2=8, 12-3-3=6, 12-0-0=12.Only 12 > 10, so for ...

Read More

Maximize number of nodes which are not part of any edge in a Graph in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 168 Views

We are given a graph containing nodes and edges. The goal is to find the maximum number of possible nodes that are connected to any edge of the graph. We know that no. of nodes will always be less than or equal to the number of edges in a complete graph.We will do this by trying to make a complete graph where the number of nodes is n then there will be n(n-1)/2 edges.edge=n(n-1)/2 (here n for nodes )2*edge=n(n-1). Once n(n-1)> no. of edges then we have extra nodes. So iterate from i=1 to i=n.Till i(i-1)>2*edge. Return n-i as result.Let ...

Read More

Counting even decimal value substrings in a binary string in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 283 Views

We are given with a string of 0’s and 1’s only. The string represents a binary number read from left to right. i.e. 001 is 4 and not 1. The goal is to find all substrings that represent an even decimal number.We will do this by checking the first value of all substrings, if it is 0 then number is even if 1 then number will be odd. Increment count by length-i as all substrings with this sbstr[0]=’0’ will be even in decimal.Let us understand with examples.Input − str=”101”Output − Count of even decimal value substrings in a binary string ...

Read More
Showing 341–350 of 809 articles
« Prev 1 33 34 35 36 37 81 Next »
Advertisements