In John’s car the GPS records every
s seconds the distance travelled from an origin (distances are measured in an arbitrary but consistent unit). For example, below is part of a record with
s = 15:
The sections are:
We can calculate John’s average hourly speed on every section and we get:
x the task is to return as an integer the
*floor* of the maximum average speed per hour obtained on the sections of
x. If x length is less than or equal to 1 return `` since the car didn’t move.
with the above data your function
gps(s, x)should return
With floats it can happen that results depends on the operations order. To calculate hourly speed you can use:
(3600 * delta_distance) / s.
The solution in Java code
Test cases to validate our solution