{"ScriptPreparationCode":null,"TestCases":[{"Name":"Using LCS","Code":"function diff(a, b) {\r\n const lcsMatrix = Array(b.length \u002B 1).fill(null).map(() =\u003E Array(a.length \u002B 1).fill(null));\r\n\r\n for (let i = 0; i \u003C= a.length; i\u002B\u002B) {\r\n for (let j = 0; j \u003C= b.length; j\u002B\u002B) {\r\n if (i === 0 || j === 0) {\r\n lcsMatrix[i][j] = 0;\r\n } else if (a[i - 1] === b[j - 1]) {\r\n lcsMatrix[i][j] = lcsMatrix[i - 1][j - 1] \u002B 1;\r\n } else {\r\n lcsMatrix[i][j] = Math.max(lcsMatrix[i - 1][j], lcsMatrix[i][j - 1]);\r\n }\r\n }\r\n }\r\n\r\n let i = a.length, j = b.length;\r\n const diffs = [];\r\n while (i \u003E 0 \u0026\u0026 j \u003E 0) {\r\n if (a[i - 1] === b[j - 1]) {\r\n i--;\r\n j--;\r\n } else if (lcsMatrix[i - 1][j] \u003E lcsMatrix[i][j - 1]) {\r\n diffs.unshift([\u0027-\u0027, i - 1, a[i - 1]]);\r\n i--;\r\n } else {\r\n diffs.unshift([\u0027\u002B\u0027, i, b[j - 1]]);\r\n j--;\r\n }\r\n }\r\n while (j \u003E 0) {\r\n diffs.unshift([\u0027\u002B\u0027, i, b[j - 1]]);\r\n j--;\r\n i--;\r\n }\r\n\r\n return diffs;\r\n}\r\ndiff(\u0022hello\u0022,\u0022hello world\u0022)","IsDeferred":false},{"Name":"Generic","Code":"const diff = (a, b) =\u003E [...a].map((c, i) =\u003E c !== b[i] \u0026\u0026 [i, b[i] || \u0027\u0027]).filter(Boolean);\r\ndiff(\u0022hello\u0022,\u0022hello world\u0022)","IsDeferred":false}]}