This question evaluates string-processing skills and combinatorial reasoning about character multisets, specifically anagram recognition, substring enumeration, and the use of efficient representations for repeated checks.
You are given a string s (letters only) and access to an English dictionary dict (a set of valid words).
Return true if every contiguous substring of s with length >= 3 can be rearranged (anagrammed) into a valid dictionary word.
Formally, for every substring t = s[i..j] with |t| >= 3, there exists some word w ∈ dict such that w is a permutation of t (same multiset of characters). Otherwise return false.
Clarifications:
Example:
t = "act"
, it passes if the dictionary contains any of
{ "act", "cat", "tac" }
.