JavaScript Solution
I used similiar technic as 1066. Campus Bike II. If you haven\'t done it, I recommend you to attempt it first.\n\nAnd This Article is my lifesaver as I\'m reall
I used similiar technic as [1066. Campus Bike II](https://leetcode.com/problems/campus-bikes-ii/). If you haven\'t done it, I recommend you to attempt it first.\n\nAnd [This Article](https://medium.com/free-code-camp/unmasking-bitmasked-dynamic-programming-25669312b77b#c94f) is my lifesaver as I\'m really shit at bit manipulation. A great introductory article to bit manipulation and the application on DP.\n```\n/**\n * @param {number[][]} workers\n * @param {number[][]} bikes\n * @return {number}\n */\nconst shortestSuperstring = (A) => {\n\tfunction additionalStr(a,b){ // a + b additional Str\n\t\tfor (let i=0; i<a.length; i++){\n\t\t\tif (b.startsWith(a.slice(i))){\n\t\t\t\treturn b.slice(a.length-i);\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\t// dp[i][j] -> min str building j state ending word i\n\tlet dp = new Array(A.length).fill()\n\t\t.map(() => new Array(1 << A.length).fill(A.join(\'\')));\n\n\tfor (let s=1; s<(1<<A.length); s++){\n\t\tfor (let j=0; j<A.length; j++){\n\t\t\tif (!(s & (1 << j))) continue;\n\t\t\tif (s===(1<<j)) dp[j][s]=A[j];\n\t\t\tlet prevS = s ^ (1 << j);\n\t\t\tfor (let k=0; k<A.length; k++){\n\t\t\t\tif (prevS & (1 << k)){\n\t\t\t\t\tlet curStr = dp[k][prevS];\n\t\t\t\t\tlet tempStr = curStr + additionalStr(curStr, A[j]);\n\t\t\t\t\tif (tempStr.length < dp[j][s].length){\n\t\t\t\t\t\tdp[j][s] = tempStr;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tlet min = Number.MAX_VALUE;\n\tlet minStr = null;\n\tfor (let i=0; i<A.length; i++){\n\t\tlet cur = dp[i][(1<<(A.length))-1];\n\t\tif (cur.length < min){\n\t\t\tmin = cur.length;\n\t\t\tminStr = cur;\n\t\t}\n\t}\n\treturn minStr;\n}\n```
['Dynamic Programming', 'JavaScript']