Coding Challenge

Job ID: 33908142

Budget: £20 – £250 GBP

I want you to do this coding scenario:

Overview
There is a queue at a festival for people to fill up their water bottles. Your task is to calculate the total time required for each person to fill up their water bottle.

Requirement
You’ll need to create a function that takes two inputs:
1. An array of integers: which represents a queue of people, and each integer is the size of their water bottle in millilitres. For instance, the array of:
[400, 750, 1000]
represents a queue of three people, where the first person in the queue has a water bottle of 400ml, the second person in the queue has a water bottle of 750ml, and the last person in the queue has a water bottle of 1 litre.
2. An integer: which represents the number of taps at the festival available for people to use for filling up their water bottles.

This function should then return the total number of seconds that it takes for all people to have filled their water bottles.

Assumptions
You must assume that as soon as one tap is free, the next person in the queue starts using that tap, and that each tap flows at a rate of 100ml per second (ie a 1 litre bottle takes 10 seconds).

1) Input validation
To stop someone using your function incorrectly, you should validate the inputs to the function and throw an error if they fail your validation.
2) Time to walk to tap
In the original challenge, we assumed that one person starts filling their water bottle as soon as the previous person finished. In reality this wouldn’t happen, since it takes time for each person to walk to the tap and open their bottle etc. You should write another function (which adapts your previous one slightly) which assumes that it takes a fixed amount of time (e.g., 2 seconds or 5 seconds) for each person to walk from the queue to the tap. (You may either assume that the initial people start at the tap, or they start at the queue and have to walk to the tap. Either is fine.)
3) Different flow rates of taps
In the original challenge, we assumed that each tap flows at a rate of 100ml per second. In reality, different taps might have more water pressure than others. You should write another function (which adapts your previous one slightly) to take account of the fact that different taps may flow at different rates (e.g., the first tap flows at 50ml per second while the second tap flows at 200ml per second). You should still assume that each person uses the first available tap.
4) Faster taps, slower time
According to your function from bonus point 3 above, is it possible for your function to output a larger number (e.g., it takes longer to fill all the bottles) if you increase the flow rate of at least one of the taps (it takes less time to fill a bottle). If yes, find an example. If no, prove it.
Related categories: Python Coding