So you've found a meeting room - phew! You arrive there ready to present, and find that someone has taken one or more of the chairs!! You need to find some quick.... check all the other meeting rooms to see if all of the chairs are in use.

Your meeting room can take up to 8 chairs. `need` will tell you how many have been taken. You need to find that many.

```if-not:java
Find the spare chairs from the array of meeting rooms. Each meeting room array will have the number of occupants as a string. Each occupant is represented by 'X'. The room array will also have an integer telling you how many chairs there are in the room.
```
```if:java
Find the spare chairs from the array of meeting rooms.
~~~java
public class Room {
  public final String occupants;  // number of occupants, each occupant is represented by 'X'
  public final int chairs;        // number of chairs in the room
}
~~~
```

You should return an array of integers that shows how many chairs you take from each room in order, up until you have the required amount.

```if-not:java
example:
[['XXX', 3], ['XXXXX', 6], ['XXXXXX', 9], ['XXX',2]] when you need 4 chairs:
```
```if:java
example:
`[Room("XXX", 3), Room("XXXXX", 6), Room("XXXXXX", 9), Room("XXX",2)]` when you need 4 chairs:
```

result -- > `[0, 1, 3]` (no chairs free in room 0, take 1 from room 1, take 3 from room 2. No need to consider room 4 as you have your 4 chairs already.

If you need no chairs, return `'Game On'`. If there aren't enough spare chairs available, return `'Not enough!'`

More in this series:

The Office I - Outed
The Office II - Boredeom Score
The Office III - Broken Photocopier
The Office IV - Find a Meeting Room

Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures
Skill types: Data structures

Starter code:
def meeting(rooms, number):
	

Solutions:
def meeting(rooms, need):
	if need == 0:
		return 'Game On'
	result = []
	for (people, chairs) in rooms:
		taken = min(max(chairs - len(people), 0), need)
		result.append(taken)
		need -= taken
		if need == 0:
			return result
	return 'Not enough!'


def meeting(rooms, number):
	if number == 0:
		return 'Game On'
	result = []
	for (taken, n) in rooms:
		available = n - len(taken)
		chairs = min(max(available, 0), number)
		number -= chairs
		result.append(chairs)
		if not number:
			return result
	return 'Not enough!'


def meeting(rooms, n):
	if n == 0:
		return 'Game On'
	(chairs, res) = ((max(0, chair - len(occ)) for (occ, chair) in rooms), [])
	for c in chairs:
		if c >= n:
			return res + [n]
		res.append(c)
		n -= c
	return 'Not enough!'


def meeting(rooms, need):
	if need == 0:
		return 'Game On'
	take = []
	for (people, seat) in rooms:
		take.append(min(need, max(0, seat - len(people))))
		need -= take[-1]
		if need == 0:
			return take
	return 'Not enough!'


from typing import List, Union

def meeting(rooms: List[List[Union[str, int]]], number: int) -> Union[List[int], str]:
	(chairs_in_rooms, chairs) = ((max(c - len(p), 0) for (p, c) in rooms), [])
	while number > 0:
		try:
			n = next(chairs_in_rooms)
			chairs.append(min(n, number))
			number -= n
		except StopIteration:
			return 'Not enough!'
	return chairs or 'Game On'


def meeting(rooms, need):
	if not need:
		return 'Game On'
	spare_chairs = []
	for (occupants, chairs) in rooms:
		available = min(need, max(chairs - len(occupants), 0))
		spare_chairs.append(available)
		need -= available
		if not need:
			return spare_chairs
	return 'Not enough!'


def meeting(rooms, number):
	if number == 0:
		return 'Game On'
	chairs = []
	for i in rooms:
		if sum(chairs) == number:
			return chairs
		if i[-1] - len(i[0]) <= 0:
			chairs.append(0)
		elif sum(chairs) + i[1] - len(i[0]) >= number:
			chairs.append(number - sum(chairs))
		else:
			chairs.append(i[-1] - len(i[0]))
	if sum(chairs) == number:
		return chairs
	if sum(chairs) < number:
		return 'Not enough!'


def meeting(rooms, number):
	if not number:
		return 'Game On'
	accumulate = []
	for r in rooms:
		available = max(r[1] - len(r[0]), 0)
		take = min(number, available)
		accumulate.append(take)
		number -= take
		if number == 0:
			return accumulate
	return 'Not enough!'


def meeting(rooms, number):
	if number == 0:
		return 'Game On'
	chairs = [max(room[1] - len(room[0]), 0) for room in rooms]
	a = []
	i = 0
	while sum(a) < number and i < len(chairs):
		a.append(min(chairs[i], number - sum(a)))
		i += 1
	return a if sum(a) >= number else 'Not enough!'


def meeting(rooms, number):
	if number == 0:
		return 'Game On'
	chairs = [room[1] - room[0].count('X') for room in rooms]
	chairs = [0 if chair < 0 else chair for chair in chairs]
	ans = []
	i = 0
	while sum(ans) < number and i < len(chairs):
		ans.append(min(chairs[i], number - sum(ans)))
		i += 1
	return ans if sum(ans) >= number else 'Not enough!'