Minimum Money Needed Leetcode Javascript Solution