PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of graph theory concepts—specifically Hamiltonian paths, graph representation parsing, and sequential edge validation— within the Coding & Algorithms domain and emphasizes practical application of graph traversal and validation rather than purely theoretical proofs.

  • medium
  • Codeium
  • Coding & Algorithms
  • Software Engineer

Validate whether a given sequence is a Hamiltonian path

Company: Codeium

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given `strArr`, an array of **three strings** describing an undirected graph and a proposed vertex visit order: 1. `strArr[0]`: a comma-separated list of vertices in parentheses, e.g. `"(A,B,C)"` 2. `strArr[1]`: a comma-separated list of undirected edges in parentheses, e.g. `"(A-B,C-D)"` 3. `strArr[2]`: a comma-separated list of vertices representing the proposed path order, e.g. `"(C,A,B)"` Task: - Determine whether the proposed order is a **Hamiltonian path**: it must visit **every vertex in the graph exactly once**, and every consecutive pair in the order must be connected by an edge. Output: - Return `"yes"` if the order forms a Hamiltonian path. - Otherwise, return the **first vertex in the given order where the path fails**, meaning the earliest vertex `order[i]` such that either: - `order[i]` is not a vertex in the graph, or - `order[i]` has already appeared earlier in the order, or - there is **no edge** between `order[i-1]` and `order[i]` (for `i > 0`). Assumptions/constraints: - The graph has at least 2 vertices and is connected. - Vertices are represented by single tokens like `A`, `B`, `X`, etc. Examples: - Input: `["(A,B,C)", "(B-A,C-B)", "(C,A,B)"]` → Output: `"yes"` - Input: `["(X,Y,Z,Q)", "(X-Y,Y-Q,Y-Z)", "(Z,Y,Q,X)"]` → Output: `"Q"` (because there is no edge between `Q` and `X`)

Quick Answer: This question evaluates understanding of graph theory concepts—specifically Hamiltonian paths, graph representation parsing, and sequential edge validation— within the Coding & Algorithms domain and emphasizes practical application of graph traversal and validation rather than purely theoretical proofs.

Parse a graph and proposed order, returning yes or the first vertex where the path fails.

Constraints

  • Graph is undirected

Examples

Input: (['(A,B,C)', '(B-A,C-B)', '(C,B,A)'],)

Expected Output: 'yes'

Explanation: Valid path.

Input: (['(X,Y,Z,Q)', '(X-Y,Y-Q,Y-Z)', '(Z,Y,Q,X)'],)

Expected Output: 'X'

Explanation: Fails at X after Q.

Input: (['(A,B,C)', '(A-B,B-C)', '(A,B,B)'],)

Expected Output: 'B'

Explanation: Repeated vertex.

Input: (['(A,B,C)', '(A-B,B-C)', '(A,B)'],)

Expected Output: 'C'

Explanation: Missing C deterministically.

Hints

  1. Check membership, duplicates, and each consecutive edge in order.
Last updated: Jun 27, 2026

Related Coding Questions

  • Find the third-largest word by length - Codeium (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.