Daily challenge for 2026-10-29
667. Alternating Room Exploration
You are given an integer n representing the number of rooms labeled from 0 to n - 1, an array colors where colors[i] is the color tag of room i, an undirected graph represented by a 2D array edges, and an integer start indicating your initial room.
A doorway between two rooms u and v can only be traversed if the two rooms have different colors (that is, colors[u] != colors[v]).
Return the total number of unique rooms you can reach starting from room start, including start itself.
Constraints:
There are 1–500 rooms and at most 2,000 undirected edges. Colors has exactly n integer entries, and all edge endpoints and the start are valid room indices. Equal color labels mean the same color. Isolated rooms and cycles are allowed.
Example:
Input: n = 4, colors = [0, 1, 0, 1], edges = [[0, 1], [1, 2], [2, 3]], start = 0
Output: 4