PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Find top-k rated nodes via traversal

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph traversal combined with streaming top-k selection, testing competencies in graph algorithms, data structure choice (e.g., visited sets and bounded heaps), tie-breaking, and reachable-node enumeration within the Coding & Algorithms domain.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Find top-k rated nodes via traversal

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a finite graph (directed or undirected) with n nodes and m edges. Each node u has an integer rating r[u]. Given a starting node s and an integer k, return the top k distinct nodes (excluding s only if specified) reachable from s by traversing edges. Break ties by smaller node ID. The graph may contain cycles. Design and implement an algorithm that: (a) visits each reachable node at most once (e.g., via BFS/DFS), (b) maintains the current top k efficiently during traversal, and (c) outputs nodes in descending rating order. Analyze time and space complexity, justify your data-structure choices (e.g., visited set and a size-k heap), and discuss how your solution changes if k is close to the number of reachable nodes, if ratings can change during traversal, or if the graph is too large to fit in memory.

Quick Answer: This question evaluates understanding of graph traversal combined with streaming top-k selection, testing competencies in graph algorithms, data structure choice (e.g., visited sets and bounded heaps), tie-breaking, and reachable-node enumeration within 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)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
|Home/Coding & Algorithms/TikTok

Find top-k rated nodes via traversal

TikTok logo
TikTok
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
5
0

You are given a finite graph (directed or undirected) with n nodes and m edges. Each node u has an integer rating r[u]. Given a starting node s and an integer k, return the top k distinct nodes (excluding s only if specified) reachable from s by traversing edges. Break ties by smaller node ID. The graph may contain cycles. Design and implement an algorithm that: (a) visits each reachable node at most once (e.g., via BFS/DFS), (b) maintains the current top k efficiently during traversal, and (c) outputs nodes in descending rating order. Analyze time and space complexity, justify your data-structure choices (e.g., visited set and a size-k heap), and discuss how your solution changes if k is close to the number of reachable nodes, if ratings can change during traversal, or if the graph is too large to fit in memory.

Submit Your Answer to Earn 20XP

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 8,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
  • AI Coding 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.