# Hackerrank’s Service Lane

I am again posting code without asymtotic analysis. There is no standard algorithm used here. I believe this problem pertains to Range Minimum Query algorithm which I hope to explore.

It is ridiculous that the code to parse the input values is more complex than the actual brute-force algorithm. Should Hackerrank parse it for us ?

```import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Solution {

private int noOfTestCases;

private ArrayList<Integer> widths = new ArrayList<>();
private ArrayList<Segment> tests = new ArrayList<>();

OutputStream outputStream = System.out;
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));

public void  getInput(BufferedReader br) throws IOException {
Scanner s = null;
int lengthHighway = 0;
try {

if (s.hasNextLine()) {
String[] s1 = s.nextLine().split("\\s+");
lengthHighway = Integer.parseInt(s1[0]);
noOfTestCases = Integer.parseInt(s1[1]);
}
if (s.hasNextLine()) {
String[] s1 = s.nextLine().split("\\s+");
for( int i = 0 ; i < s1.length ; i ++){
}
}
while (s.hasNextLine()) {
String[] s1 = s.nextLine().split("\\s+");
}
} finally {
s.close();
}
}

class Segment{

public final int entry,exit;

public Segment(int entry, int exit) {
this.entry = entry;
this.exit = exit;
}
}

public static void main( String... argv ) throws IOException {
Solution rm = new Solution();
rm.getInput(br);
rm.fit();

}

private void fit() {
int[] vehicle = new int[]{1,2,3};

try {
for( Segment test : tests){
Integer[] a  = Arrays.copyOfRange(widths.toArray(new Integer[widths.size()]), test.entry, test.exit+1);
Arrays.sort(a);
pw.println(vehicle[a[0]-1]);
pw.flush();
}
}finally{
pw.close();
}
}

}
```