← 返回 sofi 的题目列表Rooms with Two Incoming Edges to Treasure
类型:qbank
Given directed room instructions and treasure rooms, return rooms with at least two incoming rooms that also point directly to a treasure room.
Requirements
Input: string[][] instructions_room, string[] treasure_rooms.
Each instruction pair such as [a, b] means room a points to room b.
Treasure rooms also appear in the instruction-room data and the treasure list can be empty.
Output: List<String> of rooms that satisfy both conditions:
at least two rooms point to it;
it points to a treasure room.
A hashmap-based solution is expected; union-find is unnecessary.
Notes
Build an indegree map and an outgoing-neighbor map.
The statement can sound more complex than it is; reduce it to direct incoming count plus direct outgoing-to-treasure membership.