Cheapest Video Transcoding Pipeline Using at Most K Conversion Steps

Last updated: November 29, 2026

Quick Overview

Uploaded videos can be converted between formats via available transcoding steps, each with a compute cost. Given the steps, a source format, a target format and a limit K on the number of steps (to bound latency and quality loss), return the minimum total cost or -1 if impossible.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Uploaded videos can be converted between formats via available transcoding steps, each with a compute cost. Given the steps, a source format, a target format and a limit K on the number of steps (to bound latency and quality loss), return the minimum total cost or -1 if impossible.

TikTok's media processing stack converts uploads into many codec and resolution variants, and this question tests shortest path under a hop constraint. The interviewer checks that you see why plain Dijkstra is wrong here and implement a bounded Bellman-Ford with the round-copy detail that keeps hop counts honest.

What the Interviewer Expects
  • Explains why Dijkstra on cost alone can discard a path that is cheaper within the hop limit
  • Uses K rounds of Bellman-Ford relaxation
  • Relaxes from a snapshot of the previous round so each round adds at most one hop
  • Handles unreachable targets and src equal to dst
  • States O(K * E) complexity and compares to Dijkstra on (node, hops) states
Key Topics to Cover
Bellman-Ford
shortest paths
hop-constrained paths
weighted graphs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you also return the sequence of steps?
  • Each step degrades quality by some amount and total loss must stay under a budget; what changes?
  • Costs vary by time of day across data centers; how would you model that?
  • When would a Dijkstra over (format, hops used) states beat Bellman-Ford?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Directed edges (u, v, cost) with non-negative costs, n formats, source, target, and max steps K. Minimum cost path with at most K edges, else -1. If src equals dst the cost is 0 with zero steps....

High-Level Design

After round r of Bellman-Ford, best[v] should be the cheapest cost to reach v using at most r edges. Each round relaxes every edge, but must read from the previous round's array. If I updated in pla...


Submit Your Answer
Markdown supported