← Back to challenges

Four Passengers and a Driver

JavaScriptHardnumbersmathalgorithms

Instructions

A typical car can hold four passengers and one driver, allowing five people to travel around. Given n number of people, return how many cars are needed to seat everyone comfortably.

Examples

carsNeeded(5) ➞ 1

carsNeeded(11) ➞ 3

carsNeeded(0) ➞ 0

Notes

It's likely there will be a few people left over and some cars won't be filled to max capacity.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Check String for Spaces