-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterview.java
More file actions
31 lines (19 loc) · 763 Bytes
/
Copy pathInterview.java
File metadata and controls
31 lines (19 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.List;
public class Interview {
public static int budgetShopping(int n, List<Integer> bundleQuantities, List<Integer> bundleCosts) {
// Write your code here
int totalBooks = 0;
for ( int index = 0; index < bundleCosts.size(); index++ ) {
if ( n < bundleCosts.get(index) ) {
break;
}
int boughtHere = n / bundleCosts.get(index);
totalBooks = boughtHere * bundleQuantities.get(index);
n = n % bundleCosts.get(index);
}
return totalBooks;
}
public static void main(String[] args) {
System.out.println(budgetShopping(60, java.util.Arrays.asList(20, 19), java.util.Arrays.asList(24, 20)));
}
}