Ad
Fundamentals
Arrays
Fundamentals
Arrays
Fundamentals
Arrays
Fundamentals
Arrays
Fundamentals
Arrays

We travel in a car with 'x' liters of fuel and a fuel consumption expressed in liters/kilometers (both paramaters are provided). In our trip we will pass through a series of gas stations at certain kilometric points (this route will be provided to us as array). The last gas station coincides with our destination.

Make a function that returns the kilometric point in which we must refuel in order not to run out of fuel.

Indications:
If the initial fuel is not enough to reach the first gas station it returns -1.
The values of the array will always be positive natural numbers in ascending order.
Note that the car will never go further than the last station.

class Solution{
  
  public static int lastPoint (int fuel, int consumption, int[]stations){
    //DO YOUR MAGIC!!
    return -1;
  }
  
  
}