There is a bus moving in the city, and it takes and drop some people in each bus stop.
You are provided with a list (or array) of integer pairs. Elements of each pair represent number of people get into bus (The first item) and number of people get off the bus (The second item) in a bus stop.
Your task is to return number of people who are still in the bus after the last bus station (after the last array). Even though it is the last bus stop, the bus is not empty and some people are still in the bus, and they are probably sleeping there :D
Take a look on the test cases.
Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the return integer can't be negative.
The second value in the first integer array is 0, since the bus is empty in the first bus stop.
Solution:
1. Subtract the elements of a two-dimensional array.
2. All subtracted values are added and returned.
def number(bus_stops):
return sum([i - j for i,j in bus_stops])
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Initialize my name (0) | 2022.05.07 |
---|---|
Even numbers in an array (0) | 2022.05.06 |
Disemvowel Trolls (0) | 2022.05.05 |
Categorize New Member (0) | 2022.05.03 |
Are You Playing Banjo? (0) | 2022.05.02 |