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
nis an integer from 1 to 100,000.- The length of
pressesis from 1 to 100,000. - The person number
ais an integer from 0 to 1,000,000, and the post numberbis an integer from 0 ton - 1.
Examples
| n | presses | result |
|---|---|---|
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 answerSolve 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.