21/

directory
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause

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

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL