Maximum cut

Kader only likes to eat eels of length exactly 10, no more, no less. Before she eats, she may cut the eels to prepare pieces of desired length. However, she only has the time to make at most maxCuts cuts. You are given a int[] eelLengths. Each element of eelLengths is the length of one of the eels Kader has at the beginning. You are also given the int maxCuts. Return the maximum number of eels of length exactly 10 she can produce.

Examples
1)i/p={13,20,13}, 2 Returns: 3
Steps are 13 = 13/10 = 1, exactly 10 length 10 is 1.
20 = 20/10 = 2, exactly 10 length is 2, total is 3. (reached maxcuts 2). Total is 3.

2)i/p={5, 5, 5, 5}, 2 Returns: 0
All are less then 10.

3)i/p={34, 10, 48}, 4 Returns: 5
Steps are 34 = 34/10 = 3 = 3 (maxcuts 5-3= 2)
10 = 10/10 = 1 = 4
48 = 48/10 – 4 = 1(exceed maxcuts 4>2)

4)i/p={30, 50, 30, 50}, 350 Returns: 16


import java.util.Arrays; public class Cut {     public int getMaximum(int[] eel, int maxCuts) {         int tcut =0;         Arrays.sort(eel);         for(int i = 0; i < eel.length; i++) {         if(eel[i]%10 == 0) {               while(eel[i] > 10 && maxCuts >0)               {                   eel[i] -= 10;                   tcut++;                 maxCuts--;               }               if(eel[i] == 10) {                   tcut++;                 eel[i] = 0;               }             }         }         Arrays.sort(eel);         for(int i = 0; i<eel.length; i++)         {           while(eel[i] > 10 && maxCuts > 0)           {               eel[i] -= 10;             maxCuts--;             tcut++;           }         }         return tcut;     }          public static void main(String[] args) {         Cut  c = new Cut();         System.out.println(c.getMaximum(new int[]{13,20,13}, 2)==3); //3         System.out.println(c.getMaximum(new int[]{5, 5, 5, 5}, 2)==0); //0         System.out.println(c.getMaximum(new int[]{34, 10, 48}, 4)==5); //5         System.out.println(c.getMaximum(new int[]{30, 50, 30, 50}, 350)==16); //16         System.out.println(c.getMaximum(new int[]{1}, 1)==0); //0         System.out.println(c.getMaximum(new int[]{10}, 1)==1); //1         System.out.println(c.getMaximum(new int[]{20}, 1)==2); //2         System.out.println(c.getMaximum(new int[]{25,15}, 3)==3); //3         System.out.println(c.getMaximum(new int[]{25,15}, 4)==3); //3         System.out.println(c.getMaximum(new int[]{25,15}, 5)==3); //3         System.out.println(c.getMaximum(new int[]{10, 10, 10, 10, 10, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 3)==52); //52         System.out.println(c.getMaximum(new int[]{10, 10, 10, 10, 10, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 4)==54); //54         System.out.println(c.getMaximum(new int[]{10, 10, 10, 10, 10, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 5)==54); //54         System.out.println(c.getMaximum(new int[]{10, 10, 10, 10, 10, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 1000)==54); //54         System.out.println(c.getMaximum(new int[]{999}, 99)==99); //99         System.out.println(c.getMaximum(new int[]{999}, 100)==99); //99     } }
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: