Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Cycles in Graphs

MediumCoding00:00
Altana
Your interviewer · Software Engineer
In session
Interviewer

Welcome to your interview for the Software Engineer role at Altana.

The question is on your right: Detect Cycles in Graphs. Take a moment with it first.

Talk your thinking through with me if you like - when you're confident, submit your answer and I'll grade it like a real screen. You have three graded attempts to score 7/10 or better.

Only Submit answer is graded - discussion is free practice.

Problem

Explain how to detect whether a graph contains a cycle. Cover both undirected and directed graphs, and describe what traversal state you would maintain in each case.

What to Address

  • How DFS works for cycle detection
  • Why undirected graphs need parent tracking
  • Why directed graphs need recursion-stack or node-state tracking
  • How to handle disconnected graphs

Interview Signals

  • Correctly distinguishes directed vs undirected logic
  • Explains the cycle condition precisely
  • Mentions time and space complexity