directory
Version:
v0.1.0
Opens a new window with list of versions in this module.
Published: Sep 24, 2026
License: BSD-3-Clause
Opens a new window with license information.
README
¶
Name
21 - find anagrams in a string
Problem
Given a strings s and t find all anagrams of t inside s.
Example
String s is "abaab". String t is "ab".
Output is a list of strings ["ab", "ba", "ab"].
Solution
Details
Use a fixed sliding window to scan through the string to check whether sub-strings are anagrams of the target string.
Complexity, assuming s has length n and t has length k:
- Time: O(n) - scan through characters in the string.
- Space: O(1) - constant space for character frequency storage.
Directories
¶
Click to show internal directories.
Click to hide internal directories.