DEV Community

Discussion on: Top 5 hardest coding questions from recent FAANG interviews

Collapse
 
davidmmooney profile image
davidmmooney

Good overview of how to solve these questions, but remember lesson 0 is always "Read the problem statement carefully."

If you can’t reach the given amount of money with any combination of the coins, you return -1.

There's no pennies here in Canada, so remove that from the denominations list and try to return 12 cents:

int main() {
  int denoms[3] = {25,10,5};
  cout << countChange(denoms, 3, 12) << endl;
}
Enter fullscreen mode Exit fullscreen mode
$ ./countChange               
0
Enter fullscreen mode Exit fullscreen mode