given the solution and test code:
the test code given here randomly generates possible scoreWays via
for (int i = 0; i < size; ++i) {
scoreWays.add(r.nextInt(1000) + 1); // r is Random instance
}
it’s possible for duplicates to be added this way (it actually did during my test run); and if duplicates exist, then answer produced by the given solution is wrong.
for example,
given
int k = 12;
List<Integer> scoreWays = Arrays.asList(2, 3, 7);
solution outputs 4 as expected; but if you change scoreWays to include duplicates
List<Integer> scoreWays = Arrays.asList(2, 3, 7, 2);
then solution code outputs 12 instead.
i just noticed this because i was comparing my solution against one given and it was sometimes outputting different #s, and it turned out to be happening whenever scoreWays included duplicates; so either the test has to be fixed to remove duplicates from scoreWays, or solution has to be updated to handle duplicates if duplicates are supposed to be allowed.