Maximum Number of Trailing Zeros in Product of Subsets of Size K in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:18:22

267 Views

Given the task is to find the maximum number of trailing zeroes in the product of the subsets of size K, of a given array of size N.Let’s now understand what we have to do using an example −Input − Arr[] = {5, 20, 2} , K=2Output − 2Explanation − A total of 3 subsets can be created having size = 2.The product of [5, 20] is 100.The product of [20, 2] is 40.The product of [5, 2] is 10.100 has the maximum number of trailing zeros = 2. Therefore 2 is the answer.Input − Arr[] = {60, 40, 25} ... Read More

Examples of Soft References and Phantom References

AmitDiwan
Updated on 17-Aug-2020 09:17:59

294 Views

Soft references are often used to implement memory-sensitive caches. Let us see an example of soft references in Java −Example Live Demoimport java.lang.ref.SoftReference; class Demo{    public void display_msg(){       System.out.println("Hello there");    } } public class Demo_example{    public static void main(String[] args){       Demo my_instance = new Demo();       my_instance.display_msg();       SoftReference my_softref = new SoftReference(my_instance);       my_instance = null;       my_instance = my_softref.get();       my_instance.display_msg();    } }OutputHello there Hello thereA class named Demo contains a function named ‘display_msg’, that displays the relevant ... Read More

Sum of the Series 2^0 + 2^1 + 2^2 + ... + 2^n in C++

sudhir sharma
Updated on 17-Aug-2020 09:17:02

1K+ Views

In this problem, we are given a number n which defines the n-th term of the series 2^0, 2^1, 2^2, …, 2^n. Our task is to create a program to find the sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n.Let’s take an example to understand the problem, Inputn=6Output Explanation sum = 2^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 sum = 1 + 2 + 4 + 8 + 16 + 32 + 64 = 127A simple solution to the problem is by using the loop. Finding the 2^i, for each value from 0 ... Read More

Maximum Number of Segments of Lengths a, b, and c in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:16:11

296 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

Maximum Number of Pieces in N Cuts in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:14:19

794 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

Maximum Number of Parallelograms Using Given Line Segments in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:12:37

175 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 Ones in a N*N Matrix with Given Constraints in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:10:45

185 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

Maximum Number of Groups of Size 3 in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:09:27

200 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

Maximum Number of Dots After Throwing a Dice n Times in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:07:36

176 Views

Given the task is to calculate the maximum number of dots that can be expected after throwing a dice N times having M faces.The first face of the dice contains 1 dot, the second face has 2 dots and so on. Likewise the M-th face contains M number of dots.The probability of appearance of each face becomes 1/M.Let’s now understand what we have to do using an example −Input − M=2, N=3Output − 1.875Explanation − The dice has 2 sides = {1, 2}If the dice is thrown 3 times then the sample space will be = MN = 23{(1, 1, ... Read More

Unreachable Statement Using Non-Final Variable in Java

AmitDiwan
Updated on 17-Aug-2020 09:06:35

136 Views

Following is an example, wherein we will see unreachable statement using the non-final variable −Exampleclass Demo_example {    int a = 2, b = 3;    void display_msg(){       while (a < b){          System.out.println("The first variable is greater than the second");       }       System.out.println("This is an unreachable statement");    } } public class Demo{    public static void main(String args[]){       Demo_example my_instance = new Demo_example();       my_instance.display_msg();    } }Output“The first variable is greater than the second” displayed infinitelyA class named Demo_example, that defines ... Read More

Advertisements