Ways To Make Coin Change

Given an infinite supply of coins of each denomination from a list, determine the total number of distinct ways to make a change for a specified value. If making the change isn't possible, return 0.

Input:

The first line contains an integer N, which represents the total number of coin denominations.
The second line contains N integers, each separated by a space, representing the denomination values.
The third line contains an integer V, the target value for which change is to be made.

Output:

A single integer, indicating the total number of ways change can be made for the target value V.

Example:

Input:

N = 3
Denominations = [1, 2, 3]
V = 4

Output:

4

Explanation: The four ways are: (1,1,1,1), (1,1,2), (1,3), and (2,2).

Constraints:

  • 1 <= N <= 10
  • 1 <= D[i] <= 10^5
  • 1 <= V <= 2 * 10^3

Note:

Implement the function without printing anything, as output management is already handled.

AnswerBot
2d

Given coin denominations and a target value, find the total number of ways to make change.

  • Use dynamic programming to keep track of the number of ways to make change for each value up to the target val...read more

Help your peers!
Add answer anonymously...
Comviva Technology 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

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