Found 1339 Articles for C

Maximum given sized rectangles that can be cut out of a sheet of paper in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:53:52

420 Views

We are given the dimensions of the sheet of paper, it’s Length L, and Breadth B. Also, we are given the dimensions of a small rectangle, it’s length l, and breadth b. The goal is to find the maximum number of smaller rectangles that can be cut out of a sheet of paper.We will do following steps −Firstly, we will take horizontal alignment, lengths L and l of sheet and rectangle respectively. Start aligning the L by l and B by b and count the rectangles.Then also do the same in vertical alignments. Count again. Return the maximum value of ... Read More

Maximum number of candies that can be bought in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:50:11

829 Views

We are given an array of candies[] of length stored in ‘size’. Each element candies[i] has a number for candies of type i.The goal is to buy as many candies as possible for any amount of money. The conditions are as given −If you purchase X[i] of type i (0

Maximum number of 2×2 squares that can be fit inside a right isosceles triangle in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:48:50

779 Views

We are given a right isosceles triangle. Isosceles triangle is the one which has two sides of equal length. Right triangle is the one which has height(ag in fig.) and base (dg in fig.) perpendicular to each other. The goal is to find the maximum number of squares that can fit into this right isosceles triangle of side 2 sq units. The sides base or height (both equal) are taken as input. No. of squares is output.Refer to the below figure to understand the problemThe given triangle of height ag and base gd has 3 squares of side 2 each. ... Read More

Count number of 1s in the array after N moves in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:37:01

455 Views

We are given an array of size N. The array has all 0’s initially. The task is to count the no. of 1’s in the array after N moves. Each Nth move has a rule associated. The rules are −1st Move − Change element at positions 1, 2, 3, 4…………..2nd Move − Change element at positions 2, 4, 6, 8…………..3rd Move − Change element at positions 3, 6, 9, 12…………..Count the number of 1’s in the last array.Let’s understand with examples.Input Arr[]={ 0, 0, 0, 0 } N=4Output Number of 1s in the array after N moves − 2Explanation − Array after ... Read More

Maximum binomial coefficient term value in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:33:47

248 Views

We are given with a positive integer ‘N’. We have to find the maximum coefficient term in all binomial coefficients.The binomial coefficient series is nC0, nC1, nC2, …., nCr, …., nCn-2, nCn-1, nCnfind the maximum value of nCr.nCr = n! / r! * (n - r)!Input − N=4Output − Maximum Coefficient − 6Explanation − 4C0= 1, 4C1 = 4, 4C2 = 6, 4C3 = 4, 4C4 = 1Therefore, the maximum coefficient is 6 in this case.Input − N=5Output − Maximum Coefficient − 10Explanation − 5C0= 1, 5C1 = 5, 5C2 =10, 5C3 = 10, 5C4 = 5, 5C5 = 1Therefore, ... Read More

Maximize the difference between two subsets of a set with negatives in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:32:06

265 Views

We are given with an array of positive and negative integers. The task is to find the maximum difference between positive and negative subsets of elements present in the array. As we have subsets of positive and negative numbers. Then the difference (sum of positives) - (sum of negatives) will always be maximum. This is because subtracting negatives will add them. Converting all negatives into positive and adding all the elements of the array will produce the desired result. Let us see examples for understanding −Input − Arr[] = { -2, 0, -3, 8, 10, 12, -4 }Output − Maximized ... Read More

Maximum and minimum of an array using minimum number of comparisons in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:30:24

13K+ Views

We are given with an array of integers. The task is to find the minimum and maximum element of the array in the minimum number of comparisons.Input Arr[] = { 1, 2, 4, 5, -3, 91 }Output Maximum element : 91 Minimum Element : -3Explanation − Here to minimize the number of comparisons, we will initialize the maximum and minimum element with Arr[0]. And starting from the 2nd element compare each value with min and max and update accordingly.Input Arr[] = { 10, 20, 21, 31, 18, 11 }Output Maximum element : 31 Minimum Element : 10Explanation − Here also, to minimize the number ... Read More

Maximum absolute difference of value and index sums in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:28:33

961 Views

We are given with an array of integers. The task is to calculate the maximum absolute difference of value and index sums. That is for each pair of indexes (i, j) in an array, we have to calculate | Arr[i] - A[j] | + |i-j| and find the maximum such sum possible. Here |A| means absolute value of A. If array has 4 elements then indexes are 0, 1, 2, 3 and unique pairs will be ( (0, 0), (1, 1), (2, 2), (3, 3), (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3) ).Input − Arr[] ... Read More

Different ways to declare variable as constant in C and C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:40:57

884 Views

There are multiple ways of declaring constants in C and C++. First of all, we need to understand what constant is.What is a Constant?Constant means which can’t be changed. In terms of programming, constants are the fixed values that are assigned to the variables such that they can’t be altered by any other variable or component during the execution of a program. Constants can be of any data type. They are used in the programming for defining the non-changing component of a program. There are some data or variables which have fixed value like Pi have fixed float value as ... Read More

Maximum distance between two occurrences of same element in array in C

Sunidhi Bansal
Updated on 14-Aug-2020 08:05:48

2K+ Views

We are given with an array of integers. The array has multiple occurrences of the same elements. The task here is to find the maximum distance between any two same elements of the array. We will pick each element from the array starting from the left. Then we will find the last occurrence of that same number and store the difference between indexes. Now if this difference is maximum then return it.Input Arr[] = { 1, 2, 4, 1, 3, 4, 2, 5, 6, 5 }Output −Maximum distance between two occurrences of same element in array − 4Explanation − The repeating ... Read More

Advertisements