Skip to content

Commit

Permalink
Day08 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
muditmahajan21 committed May 21, 2022
1 parent a6eff56 commit 454efc0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Day08/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ Link: [https://practice.geeksforgeeks.org/problems/fractional-knapsack]
- Else, add the value of the item according to the fraction of the weight and the remain capacity.
- Break the loop and return the answer.

Time Complexity: O(nlogn)
Time Complexity: O(nlogn)

## Number of Coins

Link: [https://practice.geeksforgeeks.org/problems/number-of-coins]

- Create a dp array of V + 1 size and initialize the array to INT_MAX.
- Set the 0-th value or base value of the dp array as zero,
- For each cost from 1 to V, run a loop on i.
- Run a loop on each coin of the array from 0 to M using j.
- If the current coin value is less than the i cose, then
- Find a temp_res as the dp array value of dp[i - coins[j]].
- If the temp_res is not INT_MAX and the temp_res + 1 is less than the dp value at i, then set the dp value at i as res + 1.
- At the end, check if the value at dp[V] is INT_MAX or not. If yes, return -1, else return the value present at the index.

Time Complexity: O(M * V)

0 comments on commit 454efc0

Please sign in to comment.