FastPrepNetwork Endpoint or Cycle Boundary
Problems/Network Endpoint or Cycle Boundary

Network Endpoint or Cycle Boundary

OpenAI logoOpenAI● EasyFULLTIMENEW GRADOAPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes directed traversal to an endpoint or the node just before a repeated step. Its compute(start_node_id, from_ids, to_ids) interface uses parallel edge arrays and sparse positive labels below 5,000, with no self-links. A printed bound excludes node 1 although its example uses 1; this practice version accepts that example. On the reported edge list, starting at node 2 follows 2 to 6 to 9 to 5 and returns 5. The existing n/edges/start interface, zero-based labels, broader limits, and allowed self-loops are practice extensions. Approximate core-task source match: 95%.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on October 10, 2026! ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧ 🩷

You are given a directed network with n nodes numbered from 0 to n - 1. Each pair [from, to] in edges creates one directed edge from from to to. Every node has at most one outgoing edge.

Start at start and repeatedly follow the current node's outgoing edge.

  • If the current node has no outgoing edge, return that endpoint.
  • If following the next edge would revisit any node already seen on this walk, return the current node. It is the last node visited before the walk would repeat.

Function

findNetworkResult(n: int, edges: int[][], start: int) → int

Examples

Example 1

n = 10edges = [[1,3],[7,3],[3,4],[4,6],[2,6],[6,9],[9,5]]start = 1return = 5

The walk is 1 → 3 → 4 → 6 → 9 → 5. Node 5 has no outgoing edge.

Example 2

n = 5edges = [[0,1],[1,2],[2,3],[3,1]]start = 0return = 3

The next edge from node 3 leads to the already visited node 1, so return 3.

Example 3

n = 6edges = [[0,2],[2,4]]start = 5return = 5

The starting node already has no outgoing edge.

Constraints

  • 1 ≤ n ≤ 200000
  • 0 ≤ edges.length ≤ n
  • Every edge contains two node labels in [0, n - 1].
  • No node appears as from more than once.
  • 0 ≤ start < n

More OpenAI problems

  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int findNetworkResult(int n, int[][] edges, int start) {
        // write your code here
    }
}
Checking account…