Arrows In and Out
Each entry of arrows is a pair [a, b]: an arrow that leaves node a and points at node b. The same arrow may be listed several times, and every copy counts. An arrow may also point from a node back at itself.
Return a list of two numbers for the node node: how many arrows point at it, and how many arrows leave it. An arrow from the node to itself counts in both.
Example 1
arrows [[0,2],[1,2],[2,3]]
node 2
returns [2,1]
The arrows [0, 2] and [1, 2] point at node 2, and [2, 3] leaves it.
Example 2
arrows [[5,5],[5,1]]
node 5
returns [1,2]
The arrow from 5 to itself points at 5 and also leaves 5.
Example 3
arrows [[0,1]]
node 7
returns [0,0]
Node 7 does not appear at all.
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
- Build the Neighbor ListsBeginner
- Can You Walk ItBeginner
- Count the LinksBeginner
- Dead EndsBeginner
- Degree of Every NodeBeginner
- Everyone Knows EveryoneBeginner
- Friends in CommonBeginner
- Is There a RoadBeginner