NeetCode #585LC-2359MediumGraphs
← Back to All Problems

#585 · #2359 · Find Closest Node to Given Two Nodes(找到离给定两个节点最近的节点)

📌 Problem Statement & Constraints

You are given a directed graph where edges[i] is the single outgoing edge from node i (-1 means none), and two starting nodes node1 and node2. Return the node reachable from both that minimises max(dist1, dist2); ties break by the smallest index. Return -1 if none. Constraints: 2 <= n <= 10^5.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!