Problem Statement
In order to make its roads safer, the government of a particular country has decided to introduce a speed limit that varies throughout the day. At busy times, the speed limit will decrease to reduce the risk of a dangerous accident. You need to drive a distance of journeyLength units and want to know how long it will take you.
You are given details of the speed limit in a
Definition
- Class:
- VariableSpeedLimit
- Method:
- journeyTime
- Parameters:
- int, int[]
- Returns:
- double
- Method signature:
- double journeyTime(int journeyLength, int[] speedLimit)
- (be sure your method is public)
Notes
- Your return value must be accurate to an absolute or relative tolerance of 1E-9.
Constraints
- journeyLength will be between 1 and 100000 (10^5), inclusive.
- speedLimit will contain between 1 and 50 elements, inclusive.
- Each element of speedLimit will be between 1 and 100, inclusive.
Examples
100
{50}
Returns: 2.0
Here the speed limit doesn't change. The journey therefore takes a time of DISTANCE/SPEED = 100/50 = 2 time units.
100
{50,25}
Returns: 2.5
Now the speed limit drops to 25 every other time unit. You drive 50 units in the first time unit and 25 in the second. You reach the end of your journey halfway through the third time unit.
1000
{50,40,30,40,50}
Returns: 24.0
2058
{80,43,57,23,28,45,60,75,73,80}
Returns: 37.4
56935
{82,20,17,15,48,3,9,64,98,84,81,53,32,20}
Returns: 1272.65625
99345
{37,1,28,49,82,50,98,97,23,22}
Returns: 2039.8636363636363
64609
{49,40,5,34,50,85,86,69,81,32,96,35,27}
Returns: 1219.0104166666667
45767
{58,46,9,4,100,56,18,28,90,77,39,60,49,48}
Returns: 939.3260869565217
98803
{87,10,45,21,22,32,82,52,42,95,61,46}
Returns: 1992.3793103448277
71899
{69,92,27,67,16,16,34,49,2,99}
Returns: 1526.5882352941176
30901
{98,81,27,84,78,83,24,11,21,72,56}
Returns: 533.6385542168674
17216
{26,30,62,55,51,56,58,4,60,23,31}
Returns: 415.03333333333336
9839
{45,90,13,4,81,50,81,10,64,86,69}
Returns: 182.8395061728395
80821
{57,91,27,20,45,16,7,16,83,45,95}
Returns: 1770.9894736842105
100000
{1}
Returns: 100000.0
43552
{30,26,79,65,45,86,76,100,3,85,5,59,80,19,76,96,22,22,77,10,81,97,2,22,54,38,96,87,3,11,62,45,99,18,80,50,47,38,29,79,70,78,56,7,10,49,97,25,20,83}
Returns: 839.3544303797469
43750
{81,33,51,19,97,90,16,61,22,65,49,59,51,72,37,71,87,79,67,89,94,51,41,42,95,29,77,22,77,23,34,11,74,40,84,66,79,16,27,66,33,99,42,42,81,81,60,70,98,80}
Returns: 747.6857142857143
72693
{93,24,5,84,55,17,31,1,10,85,75,16,51,50,67,65,72,22,56,86,70,36,89,99,28,65,23,45,16,8,91,18,84,79,20,98,25,15,85,44,90,43,59,56,23,55,17,2,49,94}
Returns: 1460.6533333333334
10137
{67,12,37,44,8,20,100,30,49,10,50,68,6,25,18,73,60,12,97,89,100,36,98,79,77,79,47,78,3,2,33,22,58,16,23,38,72,63,49,67,78,31,5,90,54,2,19,17,49,57}
Returns: 219.93258426966293
46571
{69,4,31,81,27,67,47,45,53,24,63,10,64,17,48,52,3,80,28,77,1,40,7,19,33,6,88,75,16,60,8,93,81,90,12,94,15,77,67,39,82,54,49,22,62,50,28,1,9,57}
Returns: 1044.8548387096773
30930
{31,4,24,83,4,77,8,12,4,79,45,48,29,64,29,18,43,10,53,97,6,22,86,37,66,17,32,33,14,87,20,90,44,26,68,98,18,34,2,48,13,60,42,90,99,37,20,5,78,34}
Returns: 742.3571428571429
97419
{86,46,38,26,53,73,73,21,93,25,61,91,41,40,34,12,15,96,99,72,22,37,66,10,28,13,74,91,63,53,47,93,96,32,92,59,12,10,91,67,96,42,100,49,11,49,68,73,41,80}
Returns: 1766.4
12957
{74,35,100,14,89,100,55,60,100,20,83,27,85,55,3,43,54,75,95,56,50,91,71,8,78,29,29,20,85,3,59,99,49,34,45,28,20,74,71,80,32,73,85,44,25,78,76,1,33,92}
Returns: 231.7171717171717
55875
{95,91,48,10,51,63,53,35,38,85,73,68,80,56,62,58,62,51,42,15,26,24,58,12,80,74,99,20,9,70,59,95,35,57,17,22,87,72,87,77,19,34,46,74,89,80,30,95,88,38}
Returns: 995.325
36231
{17,52,26,40,73,84,58,21,23,81,69,22,1,22,32,9,74,93,78,62,10,42,10,49,8,11,96,67,12,53,92,49,17,70,58,50,14,71,27,4,65,14,57,75,63,58,11,80,92,49}
Returns: 784.7413793103449
100000
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 100000.0
100000
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
Returns: 1000.0
9839
{45, 90, 13, 4, 81, 50, 81, 10, 64, 86, 69 }
Returns: 182.8395061728395
100
{50 }
Returns: 2.0
17216
{26, 30, 62, 55, 51, 56, 58, 4, 60, 23, 31 }
Returns: 415.03333333333336
89839
{45, 90, 13, 4, 81, 50, 81, 10, 64, 86, 69, 13, 1 }
Returns: 1924.0666666666666
1
{10 }
Returns: 0.1
2058
{80, 43, 57, 23, 28, 45, 60, 75, 73, 80 }
Returns: 37.4
50
{23 }
Returns: 2.1739130434782608
5
{10 }
Returns: 0.5
76
{50, 25 }
Returns: 2.02
10
{50 }
Returns: 0.2
10
{20 }
Returns: 0.5
9850
{45, 45, 13, 4, 81, 50, 81, 10, 64, 86, 69 }
Returns: 197.79710144927537
2
{4 }
Returns: 0.5
98483
{45, 90, 13, 4, 81, 50, 81, 10, 64, 86, 69, 11 }
Returns: 1956.6888888888889
1000
{50, 40, 30, 40, 50 }
Returns: 24.0
80
{25 }
Returns: 3.2
1
{2 }
Returns: 0.5
10000
{5, 15 }
Returns: 1000.0
31
{10, 10, 10, 10 }
Returns: 3.1
100000
{1 }
Returns: 100000.0