Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Mohammed Dh Abbas
my solution

Mohammed Dh Abbas

Oct 23, 2024

class Solution: def findLPSLength(self, st): def is_palindrom(s, i, j): while i <= j: if s[i] != s[j]: return False i += 1 j -= 1 return True def dp(s, i, j, memo): if (i, j) in memo: return memo[(i, j)] if is_palindrom(s, i, j): return j - i + 1 if i > j: return 0 result = max(dp(s, i + 1, j, memo), dp(s, i, j - 1, memo)) memo[(i, j)] = result return result return dp(st, 0, len(st) - 1, {})

0

0

Comments
Comments

On this page