To prevent TLE, space complexity should be O(m) and time complexity should be O(n*m). Also add pre-check condition if len(A)<len(B): return 0


#1

Comment body goes here.


#2

No, that doesn’t required , i didn’t got tle instead of having space complexity of (m*n)