Counting Vehicles

Start Timer

0:00:00

Upvote
7
Downvote
Save question
Mark as completed
View comments (9)

Let’s say there are many vehicles on a long road. At each mile along the road, a checkpoint indicates the length traveled across the road.

You are given a list called vehicles which indicates the number of vehicles between each checkpoint. For example, the list [7,4,3] would mean that there are seven vehicles before the first checkpoint, four vehicles between the first and second checkpoints, and three vehicles between the second and third checkpoints.

Write a function range_vehicles that will give the number of vehicles between the start and end checkpoints.

Note: start may be 0

Example:

Input:

vehicles = [5, 6, 4, 2, 1]
start = 1
end = 3

Output:

range_vehicles(vehicles,start,end) -> 10
.
.
.
.
.


Comments

Loading comments