Daily challenge for 2026-10-27
665. Nearest Exit in Corridor Network
You are given an integer n representing nodes labeled from 0 to n - 1 in an undirected corridor network. You are also given an edge list edges, a list of target node indices exits, a list of blocked node indices blocked, and a starting node start.
You cannot traverse into or through any node listed in blocked. If start itself is in blocked, it cannot be traversed and no exit can be reached. If start is not blocked and is listed in exits, the shortest edge distance is 0.
Return the minimum edge distance from start to any reachable exit, or -1 if no exit is reachable.
Constraints:
There are 1–500 nodes and at most 2,000 undirected edges. All endpoints, exits, blocked nodes and the start are valid node indices. Exit and blocked lists may be empty or contain repeats. A blocked exit is unavailable.
Example:
Input: n = 5, edges = [[0, 1], [1, 2], [2, 3], [1, 4]], exits = [3, 4], blocked = [2], start = 0
Output: 2