File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
Famous-Coding-Interview-Problems Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ int vis[N][N], dp[N][N];
1111int ways (int pos, int S) {
1212 if (pos == n) return S == 0 ;
1313 int &ans = dp[pos][S];
14- if (vis[pos][S]) return ans; vis[pos][S] = 1 , ans = 0 ;
14+ if (vis[pos][S]) return ans; vis[pos][S] = 1 , ans = 0 ;
1515 int times = 0 ;
1616 while (times*A[pos] <= S) ans += ways (pos+1 , S-times*A[pos]), times++;
1717 return ans;
@@ -20,9 +20,9 @@ int ways(int pos, int S) {
2020// Faster than ways function as it causes only two transitions
2121int fasterWays (int pos, int S) {
2222 if (pos == n) return S == 0 ;
23- if (S < 0 ) return 0 ;
23+ if (S < 0 ) return 0 ;
2424 int &ans = dp[pos][S];
25- if (vis[pos][S]) return ans; vis[pos][S] = 1 , ans = 0 ;
25+ if (vis[pos][S]) return ans; vis[pos][S] = 1 , ans = 0 ;
2626 ans = ways (pos, S-A[pos]) + ways (pos+1 , S);
2727 return ans;
2828}
You can’t perform that action at this time.
0 commit comments