# JavaScript (ES6), <s> 83 82 </s> 81 bytes Returns `0` if the input string is a superpermutation, or `1` if it's not. <!-- language-all: lang-javascript --> f=(s,a=[...new Set(s)],p)=>!s.match(p)|a.some((c,n)=>f(s,a.filter(_=>n--),[p]+c)) [Try it online!](https://tio.run/##fcuxDsIgFEDR3a/QTu9FeAngSn/CsWkMQdAaCqQQXfx3tKtpXO/JfZinKXaZcuUxXV1rXkNhRg9EFN1rf3YVCo4so@4PhWZT7R0yvg2VNDsAy@JX/PqQn0J1C1x0HzlHNuTxaBGbTbGk4CikG3johFSnDnH3m7faZpRKSKHkH1upfQA "JavaScript (Node.js) – Try It Online") ### How? If all permutations of the \$N\$ symbols are present in the input string \$s\$, so are all prefixes of said permutations. Therefore, it's safe to test that all \$p\$ are found in \$s\$ even when \$p\$ is an incomplete permutation whose size is less than \$N\$. That's why we can use a function that recursively builds each permutation \$p\$ of the symbols and tests whether \$p\$ exists in \$s\$ at each iteration, even when \$p\$ is still incomplete. ### Commented f = ( // f is a recursive function taking: s, // s = input string a = [...new Set(s)], // a[] = list of unique characters in s p // p = current permutation, initially undefined ) => // !s.match(p) | // force the result to 1 if p is not found in s // NB: s.match(undefined) is truthy because it's equivalent // to looking for an empty string in s a.some((c, n) => // for each character c at position n in a[]: f( // do a recursive call: s, // pass s unchanged a.filter(_ => n--), // remove the n-th character in a[] (0-indexed) [p] + c // coerce p to a string and append c to p ) // end of recursive call ) // end of some()