How to Solve the Coin Collecting Problem in Java Using Dynamic Programming

coin collecting problem java

A variation of the coin collecting problem is to find the minimum number of coins of certain denominations that can be used to make a given sum. To do this, a table is created that holds the possible combinations of coins that can be used to form a given sum. A solution is found by recursively diving down the table and adding each coin to the current sum (solution(sol+coins[i]) + i). Each time that a new value is added, the tables are updated. This solution has a time complexity of O(sync) and an area complexity of O(sync) for sync = 1.

In this article, we will examine how to solve the coin change problem in java using dynamic programming and then compare it to a recursive approach. This method allows for the use of a much smaller set of values and thus reduces the runtime by at least an order of magnitude.

This is an advanced topic, so please read the following article if you are interested in understanding the concepts behind this solution.

Several coins are placed in cells of a nxm board, with no more than one coin per cell. A robot, starting in the upper left corner of the board, wants to collect these coins and bring them to the bottom right corner. However, it can only move down or to the left and right in the rectangle. How many coins can it collect in a single step?