Is there any logical mistake in this code?

interview-questions
programming
Tags: #<Tag:0x00007f2428615be0> #<Tag:0x00007f2428615aa0>

#1

This code gives the wrong answer for many cases…while using only recursion is giving correct answer but arter memoization it gives incoreect ans.

dp = [[-1]*501]*501
def digisum(n,s):
	if n==0: return (s==0)
	if dp[n][s]!=-1:
		return dp[n][s]
	ans = 0
	for i in range(0,10):
		if s-i>=0:
			ans+=digisum(n-1,s-i)
	dp[n][s] = ans
	return dp[n][s]
	
class Solution:
	# @param A : integer
	# @param B : integer
	# @return an integer
	def solve(self, n, s):
		ans = 0
		for i in range(1,10):
			if s-i>=0:
				ans+=digisum(n-1,s-i)
		return ans%1000000007

`