forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
55 lines (44 loc) · 1.34 KB
/
Solution.java
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
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner input = new Scanner(System.in);
int N = input.nextInt();
int T = input.nextInt();
int[] widths = new int[N];
for(int i = 0; i < N; i++)
{
widths[i] = input.nextInt();
}
for(int test = 0; test < T; test++)
{
int i = input.nextInt();
int j = input.nextInt();
int vehicleSize = 3; //Initialize to truck
while(i <= j)
{
if(vehicleSize > widths[i])
{
vehicleSize = widths[i];
}
i++;
}
System.out.println(vehicleSize);
}
}
}