Five minutes. One pattern. Stay fluent.

Daily etudes

Code echo

Share task

Today’s task: “Code echo”. Practice the Sliding window pattern! Given a nonempty string code and a string stream, both containing only lowercase Latin letters, count the contiguous substrings of stream th... https://etuder.dev

Given a nonempty string code and a string stream, both containing only lowercase Latin letters, count the contiguous substrings of stream that are anagrams of code. A match must have the same length and the same number of occurrences of each letter; order may differ. Substrings may overlap, and each starting index counts separately. If stream is shorter than code, return 0.

Example:

count_code_echo("ab", "abab")  →  3

The length-2 substrings are ab, ba and ab. All three contain one a and one b.

count_code_echo("ok", "kooko")  →  3

The length-2 substrings are ko, oo, ok and ko. All except oo contain one o and one k.

Pattern: sliding_window - a frequency window of fixed length