> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/shortest_common_supersequence.md).

# Shortest common supersequence

Uses the *lcs* function defined [here](https://rosettacode.org/wiki/Longest_common_subsequence#Sidef).

```ruby
func scs(u, v) {
    var ls = lcs(u, v).chars
    var pat = Regex('(.*)'+ls.join('(.*)')+'(.*)')
    u.scan!(pat)
    v.scan!(pat)
    var ss = (u.shift + v.shift)
    ls.each { |c| ss += (c + u.shift + v.shift) }
    return ss
}
 
say scs("abcbdab", "bdcaba")
```

#### Output:

```
abdcabdab
```
