Coin change

Given a value N, if we want to make change for N cents, and we have  infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we  make the change? The order of coins doesn’t matter.

CodingNinjas
author
2y
  • First I thought of the recursion approach but the complexity of that approach was exponential and that solution was not passing any test case, then I thought of DP approach and use the concept of incl...read more
CodingNinjas
author
2y
Recursion

  1. The idea is to use recursion.
  2. For a particular coin, we have two options either include it or exclude it.
  3. If we include that coin, then calculate the remaining number that we have to generate ...read more
CodingNinjas
author
2y
Recursion And Memoization
  1. The idea is to use recursion and memoization. So first create a 2D array 'memo' that will store the answer of all subproblems that we compute.
  2. For a particular coin, if the ans...read more
CodingNinjas
author
2y
Iterative DP
  1. The idea is to use dynamic programming.
  2. Create a two-dimensional array, ‘ways’, where ‘ways[i][j]’ will denote the total number of ways to make j value by using i coins.
  3. Fill dp array by the...read more
CodingNinjas
author
2y
Space Optimised Iterative Approach
  1. The idea is to use dynamic programming
  2. As by recurrence relation of previous approach, we can easily see that it is only dependent on previous row, so we can optimise ...read more
Add answer anonymously...
Barclays Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter