PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Reevo

Output lexicographically largest DFS traversal

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph traversal algorithms and combinatorial reasoning about node visitation order, specifically assessing the ability to manipulate depth-first search choices to produce a lexicographically maximal global sequence.

  • medium
  • Reevo
  • Coding & Algorithms
  • Software Engineer

Output lexicographically largest DFS traversal

Company: Reevo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given a graph with `n` nodes labeled `1..n` and `m` edges. Assume an undirected graph unless stated otherwise. You must output a node visitation sequence produced by a **depth-first search (DFS)** that visits every node exactly once overall, with these rules: 1. You may choose the start node of the first DFS. 2. When a DFS finishes (you have fully explored a connected component), if there are still unvisited nodes, you may start a new DFS from any unvisited node. 3. Within a DFS, when a node has multiple unvisited neighbors, you may choose the order to explore them. Among all valid full-graph DFS visitation sequences of length `n`, output the **lexicographically largest** sequence (compare sequences by the first position where they differ; the one with the larger node label is larger). Input: `n`, edge list. Output: the visitation order as `n` integers.

Quick Answer: This question evaluates understanding of graph traversal algorithms and combinatorial reasoning about node visitation order, specifically assessing the ability to manipulate depth-first search choices to produce a lexicographically maximal global sequence.

Related Interview Questions

  • Count all palindromic substrings - Reevo (medium)
  • Maximize weighted sum with disjoint adjacent swaps - Reevo (medium)
  • Check strings against dictionary efficiently - Reevo (Medium)
Reevo logo
Reevo
Feb 2, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
1
0

You are given a graph with n nodes labeled 1..n and m edges. Assume an undirected graph unless stated otherwise.

You must output a node visitation sequence produced by a depth-first search (DFS) that visits every node exactly once overall, with these rules:

  1. You may choose the start node of the first DFS.
  2. When a DFS finishes (you have fully explored a connected component), if there are still unvisited nodes, you may start a new DFS from any unvisited node.
  3. Within a DFS, when a node has multiple unvisited neighbors, you may choose the order to explore them.

Among all valid full-graph DFS visitation sequences of length n, output the lexicographically largest sequence (compare sequences by the first position where they differ; the one with the larger node label is larger).

Input: n, edge list. Output: the visitation order as n integers.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Reevo•More Software Engineer•Reevo Software Engineer•Reevo 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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.