Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 32 of 81

Maximum number of groups of size 3 containing two type of items in C++

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

Given the task is to calculate the maximum number of groups of size 3 that can be formed when N number of items of type A and M number of items of type B are given.Also, each group should have at least one item of each type, that is either A or B.Let’s now understand what we have to do using an example −Input − N=3, M=5Input − 2ExplanationGroup 1: 1 item of type A and 2 items of type B Group 2: 1 item of type A and 2 items of type B In total, 2 items of type ...

Read More

Count ways of choosing a pair with maximum difference in C++

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

We are given with an array of numbers Arr[]. The goal is to count the number of pairs whose difference is equal to the maximum difference of all possible pairs. Count pairs (i!=j) and arr[x]- arr[y] is maximum possible.We will do this by first finding the maximum difference where (i!=j). And store as maxdiff. Then count all those pairs that have difference=maxdiff.Let’s understand with examples.Input − arr[]= { 1, 2, 3, 2, 4, 1, 5 }Output − No. of ways of choosing pair with maximum difference − 2Explanation −Here minimum no. is 1 and maximum number is 5, maximum difference ...

Read More

Count the triplets such that A[i] < B[j] < C[k] in C++

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

We are given with three arrays A[], B[] and C[]. The goal is to find all triplets of elements of these arrays such that A[i]

Read More

Count total divisors of A or B in a given range in C++

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

We are given four integers L, R, A and B. The goal is to find the count of numbers in range [L, R] that fully divide either A or B or both.We will do this by traversing from L to R and for each number if number%A==0 or number%B==0 then increment count of divisors.Let’s understand with examples.Input − L=10, R=15, A=4, B=3Output − Count of divisors of A or B − 2Explanation −Number 12 is fully divisible by 3 and 4. Number 15 is fully divisible by 3 only. Total divisors=2Input − L=20, R=30, A=17, B=19Output − Count of divisors ...

Read More

Maximum number of ones in a N*N matrix with given constraints in C++

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

Given the task is to find the maximum number of ones in a binary matrix possible with the following constraints.Two integers N and X are given where X

Read More

Counting cross lines in an array in C++

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

We are given with an array of distinct elements that are unsorted. The goal is to find the cross lines after the array is sorted. Cross lines are counted as shown below −Arr[]={ 1, 2, 4, 3, 5 } There are 3 cross lines as shown belowArr[]= { 1, 2, 3, 4, 5 }. There are no cross lines as the array is already sorted.We will count the cross lines using insertion sort in which an element from right is added to sorted elements on its left. Each time the element is added in the sorted part, increment count as ...

Read More

Maximum number of parallelograms that can be made using the given length of line segments in C++

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

Given the task is to find the maximum number of parallelograms that can be made using given N number of line segments if each line segment can be used at most in one parallelogram.Let’s now understand what we have to do using an example −Input − Arr[] = {8, 3, 1, 3, 8, 7, 1, 3, 5, 3}Output − 2Explanation − With the above given line segments, the two parallelograms that can be formed are with sides 8, 1, 8, 1 and 3, 3, 3, 3 respectively.Input − Arr[] = {7, 9, 9, 7}Output − 1Approach used in the below ...

Read More

Maximum number of pieces in N cuts in C++

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

Given the task is to calculate the maximum number of square or rectangle pieces of equal size that can be obtained by cutting a given square piece in total N number of cuts horizontally or vertically.Let’s now understand what we have to do using an example −Input − N=8Output − 25Explanation − When N=8, the number of vertical cuts = 4 and the number of horizontal cuts = 4.Total pieces = 2512345678910111213141516171819202122232425Input − 7Output − 201234567891011121314151617181920Approach used in the below program as followsIf N is the number of cuts and we have to maximize the resultant pieces then equal number ...

Read More

Count the numbers divisible by 'M' in a given range in C++

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

We are given three numbers A,B and M. A and B define the range [A,B] of numbers.The goal is to count numbers between A and B that are divisible by M.We will start from i=A till first multiple of M. Increment count if i%M=0. Now increment i till i

Read More

Maximum number of segments of lengths a, b and c in C++

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

Given the task is to find the maximum number of line segments of lengths a, b and c that can be formed from given positive integer N.Let’s now understand what we have to do using an example −Input − N=8, a=3, b=1, c=2Output − 8Explanation − N can be divided into 8 segments of b which is maximum number of segments that can be made.Input − N=13, a=2, b=7, c=3Output − 6Approach used in the below program as followsIn function MaxSegment() declare an array MaxSeg[N +1] of type int and initialize it with value -1.The put the zero-th index equal ...

Read More
Showing 311–320 of 809 articles
« Prev 1 30 31 32 33 34 81 Next »
Advertisements