python/CodeChallenge_5.py

28 lines
1.0 KiB
Python

'''
Bill and Bob have recently joined the Codefinity University for Cool Engineers. They are now moving into a dormitory and want to share the same room. The dormitory has n rooms in total. Each room has a current occupancy and a maximum capacity. Your task is to determine how many rooms have enough space for both Bill and Bob to move in.
Given a list of n sublists, where each sublist contains two integers c (number of people currently living in the room) and m (room's maximum capacity), return the number of rooms where Bill and Bob can move in together.
Example 1
Input:
[[2, 2], [1, 10], [3, 5], [0, 2]]
Output:
3
'''
from typing import List
class Solution(object):
def solve(self, rooms: List[List[int]]) -> int:
print("Input rooms:", rooms)
count = 0
for c, m in rooms:
if m - c >= 2:
count += 1
return count
s = Solution()
print(s.solve([[2, 2], [1, 10], [3, 5], [0, 2]])) # Output: 3
print(s.solve([[1, 1], [2, 3], [4, 5], [0, 1], [3, 6]])) # Output: 1