## Problem Description:

Molly wants to buy laptops for her school. Find out how many laptops you can buy by comparing available providers.

Each vendor sells the laptops in batches, with an amount indicating how many laptops per batch and the cost of the entire batch.

Example Input: `50 [20,19] [24,20]`

That means Molly has to spend $ 50. The first vendor has 20 laptops per batch and each batch costs $ 24. The second vendor has 19 laptops per batch and each batch costs $ 20.

The possible answers are 40 and 38. When she buys from the first seller, she spends $ 48 (24 * 2). Since she buys 2 batches, the total amount is 40 (20 * 2).

However, if she bought from the second vendor, the maximum would be 38, as each batch has 19 laptops and runs out of money after the second batch.

The final answer is 40, because 40 is higher than 38.

This seems to be similar to the Knapsack problem.

My solution is listed below. The permute method is used to generate the possible permutations between the indices. For example, if we have 3 elements in the input field, the permutations are:

012 021 102 120 201 210

```
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.stream.IntStream;
public class ShoppingBudget {
public static void main (String[] args) {
ShoppingBudget sb = new ShoppingBudget ();
assertEquals (40, sb.budgetShopping (50, List.of (20, 19), List.of (24, 20)));
assertEquals (20, sb.budgetShopping (4, List.of (10), List.of (2)));
assertEquals (0, sb.budgetShopping (1, list.of (10), list.of (2)));
assertEquals (41, sb.budgetShopping (50, List.of (20, 1), List.of (24, 2)));
}
private void permute (int start, int moneyAvailable, int[] input indices,
list budgetquantities, list budgetCosts, maxQuantity maxQuantity) {
if (start == inputIndices.length) {// base case
int possibleMax = findSolution (inputIndices, moneyAvailable, budgetQuantities, budgetCosts);
maxQuantity.value = Math.max (maxQuantity.value, possibleMax);
Return;
}
for (int i = start; i <inputIndices.length; i ++) {
// swap
int temp = inputIndices[i];
input indices[i] = inputIndices[start];
input indices[start] = Temp;
// swap (input)[i]input[start]);
permute (start + 1, moneyAvailable, inputIndices, budgetQuantities, budgetCosts, maxQuantity);
// swap (input)[i],Entrance[start]);
int temp2 = inputIndices[i];
input indices[i] = inputIndices[start];
input indices[start] = Temp2;
}
}
private int findSolution (int[] inputIndices, int moneyAvailable,
list budgetquantities, list budgetCosts) {
int remaining = moneyAvailable;
int counter = 0;
for (int index: inputIndices) {
if (left == 0) {
break;
}
int quantity = budgetQuantities.get (index);
int cost = budgetCosts.get (index);
if (cost <= remaining) {
int howManyToBuy = remaining / costs;
counter + = howManyToBuy * number;
remaining - = (howManyToBuy * costs);
}
}
Return counter;
}
private int budgetShopping (int n, list budgetquantities,
list budgetCosts) {
int[] inputIndices = IntStream.rangeClosed (0, budgetQuantities.size () - 1) .toArray ();
MaxQuantity maxQuantity = new MaxQuantity ();
maxQuantity.value = Integer.MIN_VALUE;
permute (0, n, inputIndices, budgetQuantities, budgetCosts, maxQuantity);
return maxQuantity.value;
}
}
Class MaxQuantity {
int value
}
```