This tool can be used in two ways.
Example 1:
$ echo '{"scooters": [15, 10], "C": 12, "P": 5}' | ./coup
{"fleet_engineers":3}
Example 2:
$ cat request.txt
{"scooters": [11, 15, 13], "C": 10, "P": 5}
$ ./coup < request.txt
{"fleet_engineers":7}
$ ./coup --listen :8080
Listening on :8080...
In a separate shell:
$ curl -XPOST -d '{"scooters":[15, 10], "C":12, "P":5}' localhost:8080
{"fleet_engineers":3}
A hosted version is available under https://coup.cfapps.io
.
Example:
$ curl -XPOST -d '{"scooters":[11,15,13], "C": 10, "P": 5}' https://coup.cfapps.io
{"fleet_engineers":7}
See releases.
Make sure you have Go installed. Refer to the official docs for more details on how to install Go.
$ go get github.com/st3v/coup
$ coup --help
$ cd $GOPATH/src/github.com/st3v/coup
$ go test -v ./...
You are given a []int scooters
, which has as many elements as there are
districts in Berlin that Coup operates in. For each i
, scooters[i]
is the
number of scooters in that district (0-based index).
During a work day, scooters are maintained (batteries changed, cleaned,
checked for damages) by the Fleet Manager (FM) and possibly other Fleet
Engineers (FEs). Each FE, as well as the FM, can only maintain scooters in
one district. Additionally, there is a limit on how many scooters a single
FE may supervise: the FM is able to maintain up to C
scooters, and a FE is
able to maintain up to P
scooters. Each scooter has to be maintained by some FE or the FM.
Find the minimum number of FEs which are required to help the FM so that every scooter in each district of Berlin is maintained. Note that you may choose which district the FM should go to.
As input you are given the []int scooters
, int C
and int P
.
Result should be int
- the minimum number of FEs which are required to help the FM.
[]scooters
will contain between1
and100
elements.- Each element in
scooters
will be between0
and1000
. C
will be between1
and999
.P
will be between1
and1000
.
-
input:
{ scooters: [15, 10], C: 12, P: 5 }
expected output:
{ fleet_engineers: 3 }
-
input:
{ scooters: [11, 15, 13], C: 9, P: 5 }
expected output:
{ fleet_engineers: 7 }
Please create an application (CLI or HTTP API) which solves this problem. Create a git repository and share the code with us through github or as a tar.gz. You can choose any programming language you are familiar with; java or ruby are preferred, though.