Skip to the code
cf.
+25 XP

#145 Hidden Shuffled Token

medium

A security scanner checks whether a leaked token token appears inside a log line line with its characters shuffled: some slice of line has exactly the same characters as token, each the same number of times.

Write containsShuffled(line, token) that returns true if such a slice exists, and false otherwise.

Example 1

Input: line = "eidbaooo", token = "ab"
Output: true

ba at index 3 uses the same letters as ab.

Example 2

Input: line = "eidboaoo", token = "ab"
Output: false

a and b are never next to each other.

Constraints

  • 1 <= line.length, token.length <= 10000
  • Both strings contain lowercase letters only.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).