Minimum Cycles
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
TikTok's February OA included a graph problem called Minimum Cycles, and you're likely seeing it because cycle detection matters at their scale. The problem asks you to find the shortest cycle in a graph, or count cycles, or detect them under constraints. Without the full text you can't drill it, but the pattern is almost certainly graph traversal plus cycle detection. StealthCoder will read the exact constraints and feed you the right approach when you're live.
Pattern and pitfall
Cycle detection in graphs splits two ways: undirected (DFS with a parent check) or directed (DFS with a recursion stack). The trap is conflating the two. Minimum cycles usually means either BFS to find the shortest cycle by edge count, or in weighted graphs, using Bellman-Ford or Floyd-Warshall to detect negative cycles. TikTok tends to ask for the actual cycle length or the cycle itself, not just a boolean. The trick is recognizing whether the graph is directed, weighted, or both before you code. Most candidates waste 10 minutes guessing. On the day, if you blank on the traversal order or the visit states, StealthCoder will have the template ready.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Minimum Cycles cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Cycles FAQ
Is this a 'find the shortest cycle' or a 'count all cycles' problem?+
Almost certainly shortest cycle by edge count. Count-all-cycles is exponential and rarely asked in timed OAs. BFS from each node is the standard move. If the problem hints at distance or 'minimum', it's shortest. Test your intuition on the first example.
Do I need to handle directed and undirected graphs differently?+
Yes. Undirected uses parent-check DFS. Directed uses DFS color marking (white/gray/black). Read the problem statement carefully. If it says 'edge' without direction, assume undirected. TikTok often mixes them in follow-ups.
What if the graph has weighted edges?+
Shortest cycle becomes trickier. You may need Floyd-Warshall O(n^3) or Bellman-Ford variants. If the OA allows it, implement the simpler unweighted BFS first, then optimize. Most February TikTok reports suggest unweighted.
How do I return the cycle itself, not just the length?+
Track parent pointers during DFS or BFS. When you find a back-edge (or a revisited node), reconstruct the path from that node back to itself using parent links. This is the hidden complexity most candidates miss.
Can I solve this in under 20 minutes if I haven't seen it before?+
If it's unweighted undirected, yes. BFS from every node, track parent, detect cycle, return length. Directed is harder and takes longer. Write pseudocode first, then code. Don't overthink the first pass.