Category : dynamic-programming

When I am changing the order of isPossible function then it’s giving wrong answer otherwise present code gives correct answer. I wanted to know why this is happening. Here is the problem statement: https://leetcode.com/problems/partition-equal-subset-sum/submissions/ Here is my accepted solution class Solution { unordered_map<int, bool> um; public: bool isPossible(vector<int>&nums, int currentIndex, int sum){ if(sum == 0){ ..

Read more

I have encountered the minimum coin change problem on CodeChef and CodeForces. On both sites I have submitted my implementation using DP. This implementation given TLE error on both sites. Unfortunately, I cannot find any other implementation of this problem. I am linking the problems – CodeChef – https://www.codechef.com/problems/FLOW005 CodeForces – https://codeforces.com/problemset/problem/996/A Here is my ..

Read more

I was solving this(https://www.hackerrank.com/challenges/coin-change/copy-from/188149763) problem on Hackerrank which can be summarized as follows : Find the total number ways to exchange a certain value with the given set of coin denominations. Here is my code which got accepted: long getWays(int n, vector<long> c) { long dp[n+1]; memset(dp, 0ll, sizeof(dp)); dp[0] = 1; for(int ci=1; ci<=c.size(); ..

Read more