Question bank › Graphs Dfs
Dsa Graphs Dfs Easy

Longest Path in Pairs

You are given a directed graph represented as a list of pairs (a, b), where there is a directed edge from a to b. Your task is to find the length of the longest path starting from a given node. Implement the function `longest_path(pairs: List[Tuple[str, str]], start: str) -> int` that returns the length of the longest path from the starting node. Input format: - The first line contains an integer `n` for the number of edges. - The next `n` lines each contain two strings `u v`, indicating a directed edge from node `u` to node `v`. - The last line contains the `start` node. Output format: - Print the length of the longest path from the starting node. Example: Input: 5 A B B C A C C D D E A Output: 4

Key concepts

graphsdfspathfinding

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.