PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/TikTok

Solve Topological Sort and Anagram Indices

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving and implementation skills across graph algorithms (topological sort and cycle detection) and string algorithms (anagram substring search) in the Coding & Algorithms domain.

  • Medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Solve Topological Sort and Anagram Indices

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

1) Given a directed graph (n vertices, m edges), return a topological ordering if one exists. If the graph contains a cycle, detect it and explain how your approach identifies the cycle. Implement and compare both Kahn’s algorithm (BFS with in-degree) and a DFS-based approach; analyze time and space complexity, and discuss how to handle multiple valid orderings. 2) Given a lowercase string text and a lowercase string pattern, return all starting indices of substrings in text that are permutations of pattern. Achieve O(n) time using a fixed-size sliding window with character counts; handle repeated characters and edge cases (empty pattern, pattern longer than text).

Quick Answer: This question evaluates algorithmic problem-solving and implementation skills across graph algorithms (topological sort and cycle detection) and string algorithms (anagram substring search) in the Coding & Algorithms domain.

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
Aug 11, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0
  1. Given a directed graph (n vertices, m edges), return a topological ordering if one exists. If the graph contains a cycle, detect it and explain how your approach identifies the cycle. Implement and compare both Kahn’s algorithm (BFS with in-degree) and a DFS-based approach; analyze time and space complexity, and discuss how to handle multiple valid orderings.
  2. Given a lowercase string text and a lowercase string pattern, return all starting indices of substrings in text that are permutations of pattern. Achieve O(n) time using a fixed-size sliding window with character counts; handle repeated characters and edge cases (empty pattern, pattern longer than text).

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.