Like and unlike

Write code · Medium · §4.2 Pairs as keys

Posts are numbered from 0 to n - 1. presses holds the records of like-button presses in the order they happened. [a, b] means that person a pressed the like button on post b.

At first, every post has 0 likes. If the person who presses the button does not currently like that post, the post gains 1 like. If they currently like that post, their like is canceled and the post loses 1 like.

Complete the function solution, which returns a list of the number of likes left on each post after all the presses, in order from post 0 to post n - 1.

Function

solution(n, presses)

Constraints

Examples

npressesresult
3[[1, 0], [2, 0], [2, 0], [1, 2]][1, 0, 1]
2[[5, 1], [5, 1]][0, 0]

Starter code

def solution(n, presses):
    answer = []
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.