← Codeium Interview Insights

Codeium·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Got an OA for a Software Engineer role at Codeium. One graph problem, pretty well-defined, but the failure-case output requirement is the part that'll trip you up if you're not careful.

Questions Asked (1)

Q1

You're given three strings describing an undirected graph: one listing the vertices, one listing the edges, and one proposing a vertex visit order. Determine whether the proposed order is a valid Hamiltonian path. If it is, return 'yes'. If not, return the first vertex in the order where the path breaks down, whether that's because the vertex doesn't exist, was already visited, or there's no edge connecting it to the previous vertex.

Algorithms & Data Structures
Author's notes

The 'yes' case is straightforward enough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the input format and edge cases, then propose a linear-time algorithm using a hash set for vertices and a hash set for edges. Iterate through the proposed order, checking each vertex for existence, uniqueness, and adjacency to the previous vertex, returning the first failure or 'yes' if all pass.

Pro tip: Mention that you would validate the input (e.g., duplicate vertices in the vertex list, self-loops) and discuss how to handle them, showing attention to robustness. Also, note that the algorithm runs in O(V+E) time and O(V+E) space, which is optimal.

1. Clarify Input and Edge Cases

Ask about the format of the strings (e.g., comma-separated), whether vertices are unique, and if the graph can have self-loops or multiple edges. Confirm that the proposed order may contain vertices not in the graph.

2. Choose Data Structures

Use a hash set for O(1) vertex existence checks and a hash set of edge pairs (normalized to avoid direction) for O(1) adjacency checks. This ensures linear time complexity.

3. Iterate Through the Proposed Order

For each vertex in order, check: (a) it exists in the vertex set, (b) it hasn't been visited before, and (c) if not the first, there is an edge to the previous vertex. Return the vertex immediately if any check fails.

4. Handle Completion and Return Result

If all vertices pass and the number of vertices visited equals the total number of vertices, return 'yes'. Otherwise, if the order is shorter than the vertex set, the first missing vertex is not explicitly in the order, so return the first vertex that would be next? Actually, the problem says return the first vertex in the order where the path breaks down; if the order is incomplete, the breakdown occurs at the first vertex not in the order? Clarify: The order is given; if it doesn't include all vertices, the first missing vertex is not in the order, so we cannot return it. The problem likely expects that the order is a sequence of vertices; if it's shorter than the total vertices, the path is not Hamiltonian, but the breakdown is not at a specific vertex in the order. We should return the first vertex in the order that causes a problem, but if the order is too short, there is no such vertex. So we need to clarify: The proposed order is a list of vertices; if it doesn't cover all vertices, it's invalid, but the first breakdown might be considered at the end? The problem statement: 'return the first vertex in the order where the path breaks down'. If the order is shorter than the total vertices, the path doesn't break down at a vertex in the order; it just ends prematurely. So perhaps we should return the first vertex that is missing from the order? But that's not in the order. To resolve, we can assume the order is meant to be a permutation of all vertices; if not, the first vertex in the order that is not in the graph or repeated or not adjacent will be caught. If the order is a valid path but doesn't include all vertices, then it's not Hamiltonian, but there's no breakdown vertex. So we need to handle that case: after iterating, if the number of vertices visited is less than total, return the first vertex not in the order? But the problem says 'first vertex in the order where the path breaks down', so if the order is too short, there is no such vertex. Therefore, we should clarify that the proposed order is expected to contain all vertices; if it doesn't, we can return the first vertex that is missing? But that's not in the order. To be safe, we can check if the order length equals the number of vertices; if not, we can return the first vertex in the order that is not in the graph? That doesn't make sense. Let's re-read: 'return the first vertex in the order where the path breaks down, whether that's because the vertex doesn't exist, was already visited, or there's no edge connecting it to the previous vertex.' So the breakdown is always at a vertex in the order. If the order is shorter than the total vertices, then the path doesn't break down at any vertex in the order; it just ends. But then it's not a Hamiltonian path. So perhaps the problem assumes the order is a sequence that may or may not be complete; if it's incomplete, the first breakdown is at the first vertex that is not in the order? But that's not in the order. So to avoid ambiguity, we can assume the order is a list of vertices that may be incomplete; if it's incomplete, we can return the first vertex that is missing from the order? But the problem says 'first vertex in the order', so that doesn't work. Therefore, I think the intended interpretation is that the order is a sequence of vertices that is supposed to be a Hamiltonian path; if it's not, the first problem encountered when traversing the sequence is returned. If the sequence is shorter than the total vertices, then after processing all vertices in the sequence, we haven't visited all vertices, so the path is not Hamiltonian, but there is no breakdown vertex. In that case, we could return the first vertex that is not in the order? But that's not in the order. So perhaps we should return the first vertex in the order that is not in the graph? That would be caught. If all vertices in the order are valid and form a path, but the order doesn't include all vertices, then the path is valid but not Hamiltonian. The problem says 'determine whether the proposed order is a valid Hamiltonian path. If it is, return 'yes'. If not, return the first vertex in the order where the path breaks down'. So if it's not Hamiltonian because it's incomplete, there is no breakdown vertex. So maybe we should return the first vertex that is missing from the order? But that's not in the order. To resolve, we can assume that the proposed order is meant to be a permutation of all vertices; if it's not, we can return the first vertex in the order that is not in the graph? That would be caught. If all vertices in the order are valid and form a path, but the order is shorter than the total vertices, then the path is valid but not Hamiltonian. In that case, we could return the first vertex that is not in the order? But the problem says 'first vertex in the order', so that's not it. Therefore, I think the problem expects that the order is a sequence of vertices that may be incomplete; if it's incomplete, we can return the first vertex that is missing from the order? But that's not in the order. So to avoid this, we can assume that the order is a list of vertices that is supposed to be a Hamiltonian path; if it's not, the first problem encountered when traversing the sequence is returned. If the sequence is shorter than the total vertices, then after processing all vertices in the sequence, we haven't visited all vertices, so the path is not Hamiltonian, but there is no breakdown vertex. In that case, we could return the first vertex that is not in the order? But that's not in the order. So perhaps we should return the first vertex in the order that is not in the graph? That would be caught. If all vertices in the order are valid and form a path, but the order doesn't include all vertices, then the path is valid but not Hamiltonian. The problem says 'determine whether the proposed order is a valid Hamiltonian path. If it is, return 'yes'. If not, return the first vertex in the order where the path breaks down'. So if it's not Hamiltonian because it's incomplete, there is no breakdown vertex. So maybe we should return the first vertex that is missing from the order? But that's not in the order. To resolve, we can assume that the proposed order is meant to be a permutation of all vertices; if it's not, we can return the first vertex in the order that is not in the graph? That would be caught. If all vertices in the order are valid and form a path, but the order is shorter than the total vertices, then the path is valid but not Hamiltonian. In that case, we could return the first vertex that is not in the order? But the problem says 'first vertex in the order', so that's not it. Therefore, I think the problem expects that the order is a sequence of vertices that may be incomplete; if it's incomplete, we can return the first vertex that is missing from the order? But that's not in the order. So to avoid this, we can assume that the order is a list of vertices that is supposed to be a Hamiltonian path; if it's not, the first problem encountered when traversing the sequence is returned. If the sequence is shorter than the total vertices, then after processing all vertices in the sequence, we haven't visited all vertices, so the path is not Hamiltonian, but there is no breakdown vertex. In that case, we could return the first vertex that is not in the order? But that's not in the order. So perhaps we should return the first vertex in the order that is not in the graph? That would be caught. If all vertices in the order are valid and form a path, but the order doesn't include all

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