package main

func LCS( str1 string ,  str2 string ) string {
    // write code here
    m, n := len(str1), len(str2)
    res, end := 0, 0
    dp := make([][]int, m+1)
    
    for i := range dp {
        dp[i] = make([]int, n+1)
    }
    
    for i := 1; i <= m; i++ {
        for j := 1; j <= n; j++ {
            if str1[i-1] == str2[j-1] {
                dp[i][j] = dp[i-1][j-1] +1
            } else {
                dp[i][j] = 0
            }
            
            if dp[i][j] > res {
                res = dp[i][j]
                end = i
            }
        }
    }
    if res == 0 {
        return ""
    }
    return str1[end - res: end]
}