I know how to find the lcs of two sequences/strings, but lcs doesn't impose a restriction that the subsequence needs to be consecutive. I've tried it as follows
function lccs(a, b)
if a.length == 0 or b.length == 0
return ""
possible = []
if a[0] == b[0]
possible.push(lcs(a[1:), b[1:])
possible.push(lcs(a[1:], b))
possible.push(lcs(a, b[1:))
return longest_string(possible)
where longest_string
returns the longest string in an array, and s[1:]
means a slice of s, starting from the first character.
I've run this both inside a browser in javascript, and in golang, on a remote server where I put each call to lccs in its own goroutine, although I have no idea about the server's hardware specs, so I have no idea of the parallelization of these routines.
In both these cases, in ran way too slowly for my needs. Is there a way to speed this up?