Permutation in String

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write containsPermutation(small, big): return true if big has a stretch of small.length characters in a row that uses exactly the letters of small, each the same number of times, in any order, and false otherwise. Both strings are lowercase letters a to z, and an empty small is always found. For example, containsPermutation("ab", "eidbaooo") is true, because of "ba", but containsPermutation("ab", "eidboaoo") is false. The checks include a big of 100,000 letters and a small of 50,000, so recounting every stretch from scratch is too slow.

Your code must pass

  • Finds a rearrangement of small inside big
  • Needs the letters to be next to each other
  • Matches how many times each letter appears
  • Handles empty and too-short strings
  • Is fast enough for 100,000 letters