forked from RyanFehr/HackerRank
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
Latest commit
55 lines (44 loc) · 1.34 KB
/
Copy pathSolution.java
File metadata and controls
55 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Problem: https://www.hackerrank.com/challenges/service-lane
//Java 8
/*
N = length of the highway
T = test cases
we have N segements in our width array
T instances of
i = entry index
j = exit index
output: largest allowed vehicle
start at point i with a truck and if it doesnt fit
at any point move down in vehicle size
return vehicle size at end point j
*/
importjava.io.*;
importjava.util.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scannerinput = newScanner(System.in);
intN = input.nextInt();
intT = input.nextInt();
int[] widths = newint[N];
for(inti = 0; i < N; i++)
{
widths[i] = input.nextInt();
}
for(inttest = 0; test < T; test++)
{
inti = input.nextInt();
intj = input.nextInt();
intvehicleSize = 3; //Initialize to truck
while(i <= j)
{
if(vehicleSize > widths[i])
{
vehicleSize = widths[i];
}
i++;
}
System.out.println(vehicleSize);
}
}
}