Skip to content

Commit 6e5e5ba

Browse files
authored
Update Maximum Profit On App
1 parent e0a3495 commit 6e5e5ba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Course 2 - Data Structures in JAVA/Test 1/Maximum Profit On App

+24
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,27 @@ Sample Output 2 Explanation :
3232
Price of your app should be Rs. 67. You can get the profit Rs. 201 (i.e. 3 * 67).
3333
*/
3434

35+
import java.util.*;
36+
import java.lang.*;
37+
public class solution {
38+
39+
public static int maximumProfit(int budget[]) {
40+
41+
Arrays.sort(budget);
42+
/*for (int i=0;i<budget.length;i++)
43+
{
44+
System.out.print(budget[i]+" ");
45+
}*/
46+
//System.out.println();
47+
48+
int ans=Integer.MIN_VALUE;
49+
int n=budget.length;
50+
// sort(budget,budget+n);
51+
for(int i=0;i<n;i++)
52+
{
53+
ans=Math.max(ans,budget[i]*(n-i));
54+
}
55+
return ans;
56+
57+
}
58+
}

0 commit comments

Comments
 (0)