Notice Period

Scrambled Passcode Scan

medium

A security audit flags any keystroke log that contains a leaked passcode — even scrambled. The passcode counts as present if some contiguous chunk of the log is a rearrangement of it.

Given the passcode code and the log stream (both lowercase strings), return True if any permutation of code appears as a contiguous substring of stream, else False.

Example 1
in code = "ab", stream = "eidbaooo"
out True
"ba" is a permutation of "ab".
Example 2
in code = "ab", stream = "eidboaoo"
out False
An 'a' and 'b' exist but never adjacent.
Constraints
  • · 1 <= len(code), len(stream) <= 2000
  • · lowercase English letters only
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.