Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solution(n, m, arr1, arr2):
- dp = [[0 for _ in range(m+1)] for _ in range(n+1)]
- for i in range(n - 1, -1, -1):
- for j in range(m - 1, -1, -1):
- if arr1[i] == arr2[j]:
- dp[i][j] = dp[i + 1][j + 1] + 1
- res = 0
- for row in dp:
- for elem in row:
- res = max(res, elem)
- return res
- n = int(input())
- arr1 = list(map(int, input().split()))
- m = int(input())
- arr2 = list(map(int, input().split()))
- print(solution(n, m, arr1, arr2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement