You are given an integer `N`, representing the total count of unique nodes labeled from `0` to `N-1`. You are also provided with `messages`, a list of lists of integers. Each inner list `messages[i]` represents a specific message and contains the distinct node labels that message `i` activates. Your task is to find the minimum number of messages you need to select from `messages` such that all `N` nodes (from `0` to `N-1`) are activated. If it's impossible to activate all `N` nodes using the given messages, return -1.
Explanation: Selecting messages `[0, 1]` and `[2, 3]` activates nodes {0, 1, 2, 3}. Another valid combination is `[0, 3]` and `[1, 2]`. This is the minimum possible.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak