1
var shortestCommonSupersequence = function (str1, str2) {2
const lcs = getLCS(str1, str2);9
while (i < str1.length && str1[i] !== c) {13
while (j < str2.length && str2[j] !== c) {21
while (i < str1.length) {25
while (j < str2.length) {32
function getLCS(a, b) {33
const t = new Array(a.length + 1)35
.map(() => new Array(b.length + 1).fill(0));37
for (let i = 1; i <= a.length; i++) {38
for (let j = 1; j <= b.length; j++) {39
if (a[i - 1] === b[j - 1]) {40
t[i][j] = 1 + t[i - 1][j - 1];42
t[i][j] = Math.max(t[i - 1][j], t[i][j - 1]);50
while (i > 0 && j > 0) {51
if (a[i - 1] === b[j - 1]) {56
if (t[i - 1][j] > t[i][j - 1]) {63
return result.split("").reverse().join("");