PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/TikTok

Find start indices of anagram substrings

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in string processing, frequency-based pattern matching, and algorithmic efficiency under length constraints, testing the ability to reason about time and space trade-offs for substring searches.

  • easy
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Find start indices of anagram substrings

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given two strings: - `s`: the text string - `p`: the pattern string Return a list of all starting indices `i` such that the substring `s[i : i + len(p)]` is a permutation (an anagram) of `p`. The indices can be returned in increasing order. ### Input - `s` and `p` contain only lowercase English letters. ### Output - An array/list of integers: all valid starting indices. ### Examples 1. `s = "cbaebabacd"`, `p = "abc"` → `[0, 6]` - `s[0:3] = "cba"` is an anagram of `"abc"` - `s[6:9] = "bac"` is an anagram of `"abc"` 2. `s = "abab"`, `p = "ab"` → `[0, 1, 2]` ### Constraints - `1 <= len(s) <= 3 * 10^4` - `1 <= len(p) <= 3 * 10^4` - `len(p) <= len(s)`

Quick Answer: This question evaluates proficiency in string processing, frequency-based pattern matching, and algorithmic efficiency under length constraints, testing the ability to reason about time and space trade-offs for substring searches.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Oct 7, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0

You are given two strings:

  • s : the text string
  • p : the pattern string

Return a list of all starting indices i such that the substring s[i : i + len(p)] is a permutation (an anagram) of p. The indices can be returned in increasing order.

Input

  • s and p contain only lowercase English letters.

Output

  • An array/list of integers: all valid starting indices.

Examples

  1. s = "cbaebabacd" , p = "abc" → [0, 6]
    • s[0:3] = "cba" is an anagram of "abc"
    • s[6:9] = "bac" is an anagram of "abc"
  2. s = "abab" , p = "ab" → [0, 1, 2]

Constraints

  • 1 <= len(s) <= 3 * 10^4
  • 1 <= len(p) <= 3 * 10^4
  • len(p) <= len(s)

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Software Engineer•TikTok Software Engineer•TikTok Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.