Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 52 of 81

Maximum mirrors which can transfer light from bottom to right in C++

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

We are given with a square matrix which contains 0’s and 1’s only. 0 represents a blank or empty place and 1 means obstacle. We must find a number of mirrors that can be placed at empty cells such that these mirrors can transfer light from bottom to right. This is possible when, mirror is placed at index [i, j] and for all cells on the right in that particular row ( i ) and cells in the bottom ( j ) in that particular column have no obstacle.If the mirror is at A[i][j], then all A[i+1 to n][ j ...

Read More

Maximize the value of x + y + z such that ax + by + cz = n in C++

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

We are given with integers a, b, c, n. The goal is to maximize the sum of x, y and z such that ax+by+cz=n.From above formula, cz=n-(ax+by) z= (n- (ax+by))/cBy fixing x and y, calculate z using the above formula, for each x, y and z. Calculate sum and store the maximum such sum obtained.Inputn = 6, a = 3, b = 4, c = 5;Outputmaximum x+y+z is 2.Explanation − for x=2, y=0 and z=0 ax+by+cz=n.3*2+0*4+0*5=6 = nInputn = 4, a = 3, b = 1, c = 2;Outputmaximum x+y+z=4Explanation − for x=0, y=4 and z=4 ax+by+cz=n.0*3+4*1+0*2=4 = nApproach used ...

Read More

Maximize arr[j] – arr[i] + arr[l] – arr[k], such that i < j < k < l in C++

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

We are given with an array of integers. The goal is to maximize the value of expression −arr[j]-arr[i] + arr[l]-arr[k] ; i

Read More

Count common characters in two strings in C++

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

We are given with the two strings let’s say str1 and str2 and the task is to find the count of common characters in two strings i.e. if str1[i] = str[j], then they will be considered as a pair and count will increased to 1 and if str1[i]!=str2[j] then they willn’t be considered as a pair and count willn’t increase to 1.For ExampleInput − str1 = “hello”       str2 = “heoo” Output − count is: 3Explanation − str1[0] = str2[0] i.e. h ; str1[1] = str2[1] i.e. e ; str1[2]!=str2[2] i.e. l and o; str1[3]=str2[3] i.e. o. So, the ...

Read More

Count even and odd digits in an Integer in C++

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

We are given with an integer number and the task is to count the even numbers and the odd numbers in a digit. Also, we will keep check on whether the even digits in an integer are occurring an even number of times and also the odd digits in an integer are occurring an odd number of times.For ExampleInput − digit = 12345 Output − count for even digits = 2       count for odd digits = 3Explanation − Yes, Also, even digits are occurring even number of times i.e. 2 and odd digits are occurring odd number ...

Read More

Count factorial numbers in a given range in C++

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

We are given the range starting from an integer value holded by a variable let’s say start till the variable end and the task is to count the total number of factorial numbers available in the given range.What is a factorial numberFactorial of a number is calculated by multiplying the digits in a number while decrementing thevalue of digit by 1. It is denoted by the symbol ‘!’ i.e. 0!, 1!, 2!, 3!, 5!, ...., etc. Factorial of 0! and 1! is always 1.I.e. factorial of 2 = 2 * (2-1) = 2 * 1 = 2       ...

Read More

Count digits in a factorial in C++

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

We are given an integer value and the task is to first calculate the factorial of a number and then calculate the total number of digits in a result.What is a factorial numberFactorial of a number is calculated by multiplying the digits in a number while decrementing the value of digit by 1. It is denoted by the symbol ‘!’ i.e. 0!, 1!, 2!, 3!, 5!, ...., etc. Factorial of 0! and 1! is always 1.I.e. factorial of 2 = 2 * (2-1) = 2 * 1 = 2       factorial of 3 = 3 * (3-1) * ...

Read More

Count Fibonacci numbers in given range in O(Log n) time and O(1) space in C++

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

We are given the range having start and end numbers and the task is to calculate the total count of Fibonacci numbers available between the given range in O(Log n) time and O(1) space.What are Fibonacci numbersFibonacci numbers are the sequence of numbers known as Fibonacci sequence where every new number is the sum of the last two preceding numbers.Where, f(0) = 0 and f(1) = 1 i.e. f(0) and f(1) have fixed positions in the sequence and the calculation will start from the third number.Formula used for calculating the sequence is −Fn = Fn-1 + Fn-2Where, F0 = 0, ...

Read More

Count common prime factors of two numbers in C++

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

We are given the two numbers let’s say x and y and the task is to find the common prime factors between two numbers. Common prime factors can be found by firstly calculating the common numbers between two numbers and after that checking from the list of common factors the one which are prime numbers.For ExampleInput − x = 10 y = 20 Output − Common prime factor of two numbers are: 2 5Explanation − common primes factors between 10 and 20 are 2 and 5 only.Input − x = 34 y = 12 Output − Common prime factor of ...

Read More

Count all the numbers less than 10^6 whose minimum prime factor is N C++

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

We are given a prime number let’s say, num and the task is to calculate the count of all the numbers less than 10^6 whose minimum prime factor is equal to num.For ExampleInput − num = 7 Output − Number of prime factors = 38095 Input − num = 3 Output − Number of prime factors = 16666Approach used in the below program is as followsInput the number let’s say numStart the loop, from i to 2 and i should be less than or equals to max value and increment the value of iInside the loop, check if s_prime[i] ...

Read More
Showing 511–520 of 809 articles
« Prev 1 50 51 52 53 54 81 Next »
Advertisements