Skip to content

Instantly share code, notes, and snippets.

@Pzdrs
Created October 16, 2021 13:22
Show Gist options
  • Select an option

  • Save Pzdrs/29428009763cf8a070674acddd290c8a to your computer and use it in GitHub Desktop.

Select an option

Save Pzdrs/29428009763cf8a070674acddd290c8a to your computer and use it in GitHub Desktop.
Bill breaker
public static Map<Integer, Integer> solve(int startingValue, int[] denominals) {
Map<Integer, Integer> map = new LinkedHashMap<>();
int remaining = startingValue;
for (int currentDenominal : denominals) {
if (currentDenominal > remaining) continue;
map.put(currentDenominal, remaining / currentDenominal);
remaining %= currentDenominal;
if (remaining == 0) break;
}
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment