Run test and Submit show different results for same testcase

Hello. Today I took part in the Daily challenge and wrote code for the problem "Partition Equal Subset Sum".

When I click a Run Test call with sample

[3,3,3,4,5]

I got result: true + expected result: true

Then I clicked on Submit I got error: Output: false + Expected: true
But I did not change code between Run Test and Submit

There is a screenshot and video:

There is a code [Python 3]:

class Solution:
    def canPartition(self, nums: List[int]) -> bool:
        amount = sum(nums)
        if len(nums) == 0 or amount % 2 == 1:
            return False
        
        return self.canPartitionInner(nums, amount//2)
    
    def canPartitionInner(self, nums, amount, stats={}, index=0):
        if index == len(nums):
            return False
        
        if index not in stats:
            stats[index] = {}

        if amount not in stats[index]:
            if nums[index] == amount:
                return True
            
            if nums[index] < amount:
                if self.canPartitionInner(nums, amount - nums[index], stats, index+1) is True:
                    return True
                
            if self.canPartitionInner(nums, amount, stats, index+1) is True:
                return True
            
            stats[index][amount] = False
        
        return stats[index][amount]
Comments (2)