Problem:
Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara

Solution in Go (1.14.1) (judge verdict: Wrong Answer)

package main

import (
	"fmt"
	"math"
)

func main() {
	var str1, str2 string
	fmt.Scanf("%s%s", &str1, &str2)
	ans := lcs(str1, str2)
	fmt.Println(ans)
}

func lcs(str1 string, str2 string) string {
	dp := createTable(len(str1), len(str2))
	for i := 1; i <= len(str1); i++ {
		for j := 1; j <= len(str2); j++ {
			if str1[i-1] == str2[j-1] {
				dp[i][j] = 1 + dp[i-1][j-1]
			} else {
				dp[i][j] = int(math.Max(float64(dp[i-1][j]), float64(dp[i][j-1])))
			}
		}
	}
	var ans []rune
	j := len(str2)
	for i := len(str1); i > 0 && j > 0; {
		if dp[i][j] == int(math.Max(float64(dp[i-1][j]), float64(dp[i][j-1]))) {
			if dp[i-1][j] >= dp[i][j-1] {
				i--
			} else {
				j--
			}
		} else if dp[i][j] == dp[i-1][j-1]+1 {
			ans = append(ans, rune(str1[i-1]))
			i--
			j--
		}
	}
	return reverse(string(ans))
}

func reverse(str string) string {
	if len(str) == 0 {
		return ""
	}
	reversed := make([]rune, len(str))
	for i := 0; i <= len(str)/2; i++ {
		reversed[i], reversed[len(str)-1-i] = rune(str[len(str)-i-1]), rune(str[i])
	}
	return string(reversed)
}

func createTable(n int, m int) [][]int {
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, m+1)
	}
	dp[0][0] = 0
	return dp
}