I often get asked: how do I practice for interview code exercises, and do something useful at the same time? Here is an idea.

COVID-19 had severely affected cinemas and theatres. As of June 2020, most countries will allow them to reopen under some restrictions. A frequent restriction is to disallow customers on consecutive seats, unless they belong to the same household.

The problem

Write a program that allocates cinema seats so that there is a minimum of one empty seat between households. Here are the inputs:

1 -> 10
2 -> 5
4 -> 3

As most interview coding exercises, requirements are not fully defined; in an interview setting, you would be encouraged to ask questions such as:

Equally, think about follow up questions that an interviewer would typically ask:

When you finish, package your solution and email it to your local cinema and theatre. Stay safe and be kind to each other.