Skip to content

Commit

Permalink
Create Buy Maximum Stocks if i stocks can be bought on i-th day.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahima507 authored Dec 24, 2023
1 parent 3fed40b commit cf5cacb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Buy Maximum Stocks if i stocks can be bought on i-th day.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public static int buyMaximumProducts(int n, int k, int[] price) {
// code here
long arr[] = new long[n];
for(int i=0; i<n; i++) arr[i] = price[i]*100000 + (i+1);

Arrays.sort(arr);

int count = 0;
for(int i=0; i<n; i++){
int day = (int)arr[i]%100000;
int pr = (int)arr[i]/100000;

if(pr*day<=k){
count+=day;
k = k-pr*day;
}
else{
count+=(k/pr);
k = k-pr*(k/pr);
}
}
return count;
}
}

0 comments on commit cf5cacb

Please sign in to comment.