Who Points at Me
Each entry of arrows is a pair [a, b]: an arrow from node a to node b. The same arrow may be listed several times, and an arrow may point from a node back at itself.
Return the nodes that have an arrow pointing at node, in increasing order and each only once. If an arrow points from node at itself, node is in the answer too.
Example 1
arrows [[3,1],[1,2],[0,1]]
node 1
returns [0,3]
The arrows from 3 and from 0 point at node 1. The arrow [1, 2] leaves node 1 and does not count.
Example 2
arrows [[4,4],[2,4],[2,4]]
node 4
returns [2,4]
Node 4 points at itself, and the arrow from 2 is listed twice but 2 appears once.
Example 3
arrows [[0,1]]
node 6
returns []
No arrow points at node 6.
Constraints
- nodes are numbered
0to11 0 <= len(arrows) <= 30
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Graphs problems
- Busiest NodeEasy
- Cable GroupsEasy
- Count the LakesEasy
- Everything Needed FirstEasy
- Everything ReachableEasy
- Farthest VillageEasy
- Fewest HopsEasy
- Follow the ArrowsEasy