Maximum Money That Can Be Withdrawn in Two Steps in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:58:45

235 Views

We are given two lockers, say L1 and L2 that have some amount of money in the form of coins. L1 has A coins and L2 has B number of coins in it. We have to withdraw money or coins from the lockers such that the money drawn out is maximum. Each time the coins are drawn from any locker, it is replaced by coins 1 less than its previous count. If we draw A coins from L1 then it will be replaced by A-1 coins and if we draw B coins from L2 then it will be replaced by ... Read More

Maximum Difference Between Group of K Elements and Rest of Array in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:56:45

578 Views

We are given with an array of integers of size N and a number k. The array consists of integers in random order. The task is to find the maximum difference between the group of k-elements and rest of the array. The array will be divided into two parts. The first part is a group of k-elements taken out and the second part is the rest of the elements of the array. We have to select k elements such that the difference between the sum of elements in both groups is maximum.If k is smaller ( half of array size) ... Read More

Maximum Difference Between First and Last Indexes of an Element in Array in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:54:28

568 Views

We are given with an array of integers of size N. The array consists of integers in random order. The task is to find the maximum difference between the first and last indexes of an element in the array. We have to find a number which appears twice in the array and the difference between its indexes is maximum. If there are more such pairs then we will store the maximum such difference between the indexes.Input Arr[] = { 2, 1, 3, 1, 3, 2, 5, 5 }.Output −Maximum difference between first and last indexes of an element in array − ... Read More

Maximum Difference Between Two Elements in C

Sunidhi Bansal
Updated on 14-Aug-2020 07:52:29

1K+ Views

We are given with an array of integers of size N. The array consists of integers in random order. The task is to find the maximum difference between two elements such that the larger element appears after the smaller number. That is Arr[j]-Arr[i] is maximum such that j>i.Input Arr[] = { 2, 1, 3, 8, 3, 19, 21}.Output −The maximum difference between two elements such that the larger element appears after the smaller number − 20Explanation − The maximum difference is between 21 and 1 and 21 appears after 1 in the array.Input Arr[] = {18, 2, 8, 1, 2, 3, 2, ... Read More

Maximum Area Rectangle by Picking Four Sides from Array in C++

Sunidhi Bansal
Updated on 14-Aug-2020 07:50:40

561 Views

The area of the rectangle is calculated as a product of its sides. All rectangles have four sides such that opposite sides are equal. For calculating the area we require length and breadth as two sides. So that we can get desired result −Area rectangle = length X breadthWe are given an array such that it consists of sides of a rectangle. The array contains values for all four sides in random order. The task here is to find two highest pairs of sides from the array in order to get the maximum area possible for the rectangle.Input Arr[] = { ... Read More

Maximum and Minimum Element of a Linked List Divisible by K in C++

Sunidhi Bansal
Updated on 14-Aug-2020 07:48:58

192 Views

A linked list is a linear data structure in which elements are linked via pointers. Each element or node of a linked list has a data part and link, or we can say pointer to the next element in sequence. The elements can take noncontiguous locations in memory.We are given a singly linked list in which there is a data part and link to the next element. The other input is a number K. Task is to find the Maximum and Minimum element of a linked list which is divisible by the number K. The linear linked list can only ... Read More

Maximum Adjacent Difference in an Array in its Sorted Form in C++

Sunidhi Bansal
Updated on 14-Aug-2020 07:45:48

1K+ Views

We are given with an array. The array need not be sorted. The task is to find the maximum difference between adjacent elements of that array in its sorted form. So the first thing is to sort the array in increasing or decreasing order. Then we will iterate the array and calculate the adjacent difference of Arr[i+1]-Arr[i]. Then for each iteration we will compare this difference with the one which is found maximum so far.Input − Arr[] = [ 1, 5, 10, 2, 7 ]Output − Maximum adjacent difference in array in its sorted form is 3.Explanation − Sorted Arr[] ... Read More

Maximize Probability of One Type from N Containers in C++

Sunidhi Bansal
Updated on 14-Aug-2020 07:40:16

160 Views

Probability Pi= (No. of Favourable Outcomes) / (Total no. of Outcomes).Given is a number N which is the number of containers present. And we have N copies of two numbers X and Y. The task is to divide copies of one number X into N containers such that the probability of drawing a copy of X is maximum. From above it can be seen that to maximize Pi, we can either maximize the numerator ( No. of favourable outcomes) or minimize the denominator(Total no. of Outcomes). This can be done in a manner that only one container has a copy ... Read More

Maximize Volume of Cuboid with Given Sum of Sides in C++

Sunidhi Bansal
Updated on 14-Aug-2020 07:38:44

259 Views

We are given with a sum of sides of a cuboid. A cuboid has three sides length, breadth and height. The volume of cuboid is calculated as a product of all three sides.Volume of Cuboid = Length X Breadth X HeightThe maximum volume can be achieved if all three sides are as close as possible.Let’s now understand what we have to do using an example −For Example The problem given here provides us with the sum of sides, say S. And let sides be L, B, H. In order to maximize the volume we have to find the sides as close ... Read More

Maximize Value of A by Replacing Digits with B in C++

Sunidhi Bansal
Updated on 14-Aug-2020 07:36:41

173 Views

The task is to maximize the value of number A by replacing some of its digits with digits present in another number B. No digits will be replaced if A’s value cannot be maximized.Note − a digit from B can be used only once.Let’s now understand what we have to do using an example −Input A = “1221” B = “1211”Output Maximum value of A possible 2221Explanation − We here select 2 from B and replace it with the first 1 of A. Here it is the only choice as replacing any other digit of A with either 2 or 1 will ... Read More

Advertisements