Challenge: The Coin Change Problem
Let's solve a coding challenge on the different ways to represent a given number of cents.
We'll cover the following
Problem statement
Given an infinite number of (25 cents), (10 cents), (5 cents), and (1 cent), write code to calculate the number of ways to represent n
.
Input
The inputs are the values of the coins available to represent the cents with (the denominations) and the number of cents.
Output
The output is the number of ways that the given number of cents can be represented.
Sample input
int amount = 10;
int denoms = [25,10,5,1]
Sample output
4
Coding exercise
Take a close look and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the hint and solution provided in the code tab. Good Luck!
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.