Correct Change
Premium Content - Free Preview
In the Kingdom of Zumbania, the Currency printer can only print the digit 1
. Thus they have 3 different denominations: 1
, 11
, and 111
. You need to determine if you can reach a certain sum with a given set of coins.
You will be given a line of input (as an array) consisting of 4 integers for the number of 1-coins, 11-coins, 111-coins, and the desired sum.
For example, the input 1 2 3 356
means there's 1
1-coin, 2
11-coins, 3
111-coins and a desired sum of 356
.
End of Free Content Preview. Please Sign in or Sign up to buy premium content.
Comments
Florian K
May 26, 9:37 AMshouldn't the 3rd Test Input be true too? 3 (3*1) + 33 (3*11) + 333 (3*111) = 369
Learneroo
May 26, 9:39 AM@Florian, you need to select the correct change exactly. 369 is not equal to 365, and there's no way to get 365 with those coins.
Patrick Lu
Jul 1, 6:23 PMI have a solution but I think there is a better way to do it. Is there a solution that we can see?
Learneroo
Jul 1, 7:27 PM@Patrick Lu, I added a featured answer, see also the Learneroo blog.