Skip to main content
5 of 8
minor update
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6),  83  82 bytes

Returns a Boolean value.

f=(s,a=[...new Set(s)],p)=>s.match(p)&&a.every((c,n)=>f(s,a.filter(_=>n--),[p]+c))

Try it online!

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) &&           // abort 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.every((c, n) =>       // otherwise, 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 every()
Arnauld
  • 197.7k
  • 20
  • 179
  • 650