Minimum Coins
Of all the possible coin combination, return the one with the fewest coins.
The problem
Write a function minChange that takes in an amount and an array of coins. The function should return the minimum number of coins required to create the amount. You may use each coin as many times as necessary. If it is not possible to create the amount, then return -1.
https://structy.net/problems/min-change
This one took me much longer than I thought, and I still had a sub-optimal solution. It was like the solution was just out of reach the whole time.. I was hung up on how to make the code return -1 if something wasn't possible. With that, I then struggled to know if a certain branch of the recursive tree was even possible. So I explored a way to return both if the branch led to a viable solution, and then the count alongside it. That I think was my third attempt, and I was still struggling. I decided I needed to simplify my approach, so I just wanted to find all possible combination, and from there I could .reduce
to the smallest one.. not optimal, but a start... Here's what I managed to get before just looking at the solution:
I want to return to this and make it work better. I want to find how to memoize it, and maybe find the bottom up approach to it.
I guess the challenge is kind of nice, but it's definitely not fun. React is fun. Tailwind is fun. This is fucking boring and frustrating. But I guess you just eat the shit until you know it (at least memorize it) and then it doesn't taste so much like shit anymore.