← Reevo Interview Insights

Reevo·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Interviewed for a software engineering role at reevo and got a graph traversal problem that looked straightforward until the lexicographic ordering requirement showed up. One coding round, algorithmic focus.

Questions Asked (1)

Q1

Given an undirected graph with nodes labeled 1 through n, return the lexicographically largest DFS traversal sequence. Start from node 1 for its connected component, then handle remaining components by visiting each from its largest node, ordering the components themselves by their max node value descending.

Algorithms & Data Structures
Author's notes

I got the basic DFS part fine but the multi-component ordering tripped me up for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem's component ordering rule, then design a DFS that always explores neighbors in descending order to maximize the sequence. Use a visited set and iterate components by their maximum node value in descending order, starting with node 1's component.

Pro tip: Mention that sorting adjacency lists in descending order ensures the lexicographically largest DFS sequence, and precomputing component max nodes avoids redundant traversals.

1. Clarify the problem

Confirm that the graph is undirected, nodes are 1..n, and the output is a sequence of nodes. Ensure understanding of component ordering: first component containing node 1, then remaining components sorted by their maximum node value descending.

2. Preprocess the graph

Build adjacency lists and sort each list in descending order. This ensures that during DFS, we always visit the largest possible neighbor first, yielding the lexicographically largest sequence.

3. Identify components and their max nodes

Use a union-find or DFS/BFS to find all connected components and record the maximum node in each. This allows ordering components correctly.

4. Perform DFS in the required order

Start DFS from node 1, then process remaining components in descending order of their max node. During each DFS, recursively visit neighbors in descending order, appending nodes to the result.

5. Return the result

After all components are visited, return the accumulated sequence as the lexicographically largest DFS traversal.

Key Points to Mention

  • Lexicographically largest DFS requires exploring neighbors in descending order.
  • Component ordering: first component must contain node 1, then others sorted by max node descending.
  • Use a visited set to avoid revisiting nodes.
  • Pre-sorting adjacency lists in descending order simplifies the DFS logic.
  • Union-Find or DFS can be used to identify components and their max nodes.
  • Time complexity: O(V + E log E) due to sorting adjacency lists, or O(V + E) if using counting sort for small labels.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.