Ad
Fundamentals
Arrays

Added random test.

Fundamentals
Arrays

Implemented a system that give you an array with of n lenght and without repetitive number sorted.

Fundamentals
Arrays

This solution goes through the array in inverted order, and if it difference of fuel to reach that station is higher or equal to zero returns the station.

Code
Diff
  • class Solution{
      
      public static int lastPoint(int fuel, int consumption, int[] stations) {
            for (int station = stations.length -1; station >= 0; station--) {
                int difference = fuel - (consumption * stations[station]);
                if ( difference >= 0) {
                    return stations[station];
                }
            }
    
            return -1;
        }
      
      
    }
    • class Solution{
    • public static int lastPoint (int fuel, int consumption, int[]stations){
    • //DO YOUR MAGIC!! YES
    • return -1;
    • }
    • public static int lastPoint(int fuel, int consumption, int[] stations) {
    • for (int station = stations.length -1; station >= 0; station--) {
    • int difference = fuel - (consumption * stations[station]);
    • if ( difference >= 0) {
    • return stations[station];
    • }
    • }
    • return -1;
    • }
    • }
Fundamentals
Arrays

Modified test that expected 45, change initial fuel amount to 250 from 80

Fundamentals
Arrays

This fork add cases that test what should happen if:

  1. Stop to refuel in the course.
  2. Overpass the destination.
  3. Even reach to first station.
Code
Diff
  • class Solution{
      
      public static int lastPoint (int fuel, int consumption, int[]stations){
        //DO YOUR MAGIC!! YES
        return -1;
      }
      
      
    }
    • class Solution{
    • public static int lastPoint (int fuel, int consumption, int[]stations){
    • //DO YOUR MAGIC!!
    • //DO YOUR MAGIC!! YES
    • return -1;
    • }
    • }