2022-06-19 07:42:49
Christmas Eve code in java :
public class Example2 {
// this will be the solution
static int solutionCount = 0;
public static void canCollect(int remainingAmount, int remainingHouses, int previousAmount) {
if (remainingHouses == 0)
return;
if (remainingAmount < 0)
return;
if (remainingAmount == 0) {
solutionCount++;
return;
}
for (int i = 1; i < previousAmount; i++) {
//deduct amount collected from this house-visit (i), deduct 1 from remaining houses, and set previousAmount to what you are collecting here
canCollect(remainingAmount - i, remainingHouses - 1, i);
}
}
// This is your solution function, although you'll need to change it enough to satisfy test-cases.
public static int solutionFunction(int x, int y) {
for (int i = 0; i <= x; i++) {
canCollect(x - i, y-1, i);
}
return solutionCount;
}
//main is just to execute it here. Omit it in your submission
public static void main(String args[]) {
System.out.println(solutionFunction(5,5)); //3
}
}
Java
Christmas Eve
Telegram - t.me/codingsolution_IT
8.6K views04:42