jusohatam

Untitled

Sep 29th, 2020
1,077
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def solution(n, m, arr1, arr2):
  2.     dp = [0 for _ in range(m+1)]
  3.     res_max = 0
  4.     for i in range(n-1, -1, -1):
  5.         for j in range(m):
  6.             if arr1[i] == arr2[j]:
  7.                 dp[j] = dp[j+1] + 1
  8.             else:
  9.                 dp[j] = 0
  10.             res_max = max(res_max, dp[j])
  11.     return res_max
  12.  
  13.  
  14. n = int(input())
  15. arr1 = list(map(int, input().split()))
  16. m = int(input())
  17. arr2 = list(map(int, input().split()))
  18. print(solution(n, m, arr1, arr2))
  19.  
RAW Paste Data