Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 34 of 81

Product of first N factorials in C++

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

Given a number N, the task is to find the product of first N factorials modulo by 1000000007. . Factorial implies when we find the product of all the numbers below that number including that number and is denoted by ! (Exclamation sign), For example − 4! = 4x3x2x1 = 24.So, we have to find a product of n factorials and modulo by 1000000007..Constraint 1 ≤ N ≤ 1e6.Input n = 9Output 27Explanation 1! * 2! * 3! * 4! * 5! * 6! * 7! * 8! * 9! Mod (1e9 + 7) = 27Input n = 3Output 12Explanation 1! * 2! * 3! mod (1e9 ...

Read More

Product of factors of number in C++

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

Given a number n we have to find its all factors and find the product of those factors and return the result, i.e, the product of factors of a number. Factors of a number are those numbers which can divide the number completely including 1. Like factors of 6 are − 1, 2, 3, 6.Now according to the task we have to find the product all the factors of the number.Input − n = 18Output − 5832Explanation − 1 * 2 * 3 * 6 * 9 * 18 = 5832Input − n = 9Output − 27Explanation − 1 * 3 * 9 = 27Approach used below is as follows to solve the problem −Take the input num .Loop from i = 1 till i*i

Read More

Product of maximum in first array and minimum in second in C

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

Given two arrays arr1[] and arr2[] of some size n1 and n2 respectively, we have to find the product of maximum element of first array arr1[] and minimum element of the second array arr2[].Like we have elements in arr1[] = {5, 1, 6, 8, 9} and in arr2[] = {2, 9, 8, 5, 3} so the maximum element in arr1 is 9 and the minimum element in arr2 is 2 so the product of both is 9*2 = 18, likewise we have to write a program to solve the given problem.Input arr1[] = {6, 2, 5, 4, 1} arr2[] = {3, ...

Read More

Product of N with its largest odd digit in C

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

Given a number N with we have to product the number with its largest odd digit. If there is no odd digit then print -1.Like we have initialized N with “153” and the largest odd digit in this number is 5 so the result would be the product of 153 with 5 i.e. 153 * 5 = 765 and if the number has no odd digit like 246 then the output must be -1.Input − N = 198Output − 1782Explanation − 198 * 9 = 1782Input − N = 15382Output − 76910Explanation − 15382 * 5 = 76910Approach used below ...

Read More

Count Magic squares in a grid in C++

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

We are given with a matrix of numbers. The goal is to find the number of Magic squares present inside the given matrix.A Magic Square, if taken as a matrix, is a 3X3 matrix which contains the elements ranging from 1 to 9 just like a grid in Sudoku. Properties are −All numbers occur exactly once.Sum of all 9 cells in the matrix is 45.Sum of each row of 3 is 15.Sum of each column of 3 is 15.Sum of diagonals of 3 is 5.To get such sums, 5 is always in the middle of both diagonals.Inputint arr[][]= { { ...

Read More

Maximum in an array that can make another array sorted in C++

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

We are given an array of numbers say Arr1[] and another array Arr2[] of same or different length. The Arr1[] has elements sorted in ascending order, such that a single element is unsorted. We must find the element from the second array Arr2[] such that it can replace the wrongly placed element of Arr1[] and make it sorted. Also, the element chosen from Arr2[] should be maximum if there are multiple options available.InputArr1[]= { 1,3,5,7,2,11 }, Arr2[]= { 4,8,7,10,9 }OutputMaximum element that can make Arr1 sorted: 10Explanation − Numbers in Arr2[] that can make Arr1[] sorted − 8,9,10 as they all are >=7 and =12 and

Read More

Maximum litres of water that can be bought with N Rupees in C++

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

We are given N rupees. The goal is to buy maximum water possible with the money where the rates of water bottles are as follows −Plastic Bottles: A Rupees for 1 litreGlass Bottles: B Rupees for 1 litreGlass Bottles: B Rupees for 1 litreNow the original cost of glass bottles becomes B-E rupees. After returning.If the cost of plastic bottles is still less than B-E, then only buy plastic bottles. Else buy N-E/B-E glass bottles and spend rest on plastic bottles.InputN = 6, A = 5, B = 4, E = 3;OutputMaximum litres of water: 3Explanation − B-E=1, 1A n/a= ...

Read More

Maximum length of balanced string after swapping and removal of characters in C++

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

We are given a string containing (, ), {, }, [, ] characters only. The goal is to find the maximum length of such string so that it becomes balanced by swapping adjacent characters or removing a character. We will do this by comparing adjacent characters, if they are opposite of each other then they can be swapped. ( }{, )(, ][ can be swapped, while {{, )), [[, }}, )), ]] cannot be swapped ).Also if a character has no matching pair, then it can be removed also. ( “{{}][“, here first { can be removed and balanced string ...

Read More

Count Derangements (Permutation such that no element appears in its original position) in C++

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

Derangement is permutation of N numbers such that no number appears at original position. For example one possible derangement of { 1, 2, 3 } is { 2, 1, 3 }. No element in this is at its original position. The goal here is to count the possible derangements for N numbers.We will do this using a recursive solution. For following no. of elements −N=0, no derangement, return 1N=1, only one number, return 0N=2, only one swap of position possible, { 1, 2 } → { 2, 1 }, return 1N=3, 2 possible permutations eg, { 1, 2, 3 } ...

Read More

Container with Most Water in C++

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

We are given an array of height of the walls of the container. The goal is to find the container that can contain the maximum volume of water. As heights of walls are elements of an array, the distance between them is considered as width between two walls. For example walls of height Arr[i] and Arr[j] have j-i width between them ( 0

Read More
Showing 331–340 of 809 articles
« Prev 1 32 33 34 35 36 81 Next »
Advertisements