Search
⌘K
Get Premium
Leetcode 1129. Shortest Path with Alternating Colors
Find the shortest distance from node 0 to every node in a directed graph whose edges are colored red or blue, with the constraint that consecutive edges along the path must alternate colors; return -1 for nodes that cannot be reached under this constraint. This is typically solved by BFS over states that pair a node with the color of the incoming edge to enforce alternation and avoid revisiting the same state.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.