My program works on my computer, but fails to compile with the codechef’s compiler. It is weird that I have used the same data structure in previous questions, but did not get any errors.
Main.java:12: illegal start of type
private static final Map<Integer, Integer> timeSlots = new
LinkedHashMap<>();
^ 1 error
My code is as follows.
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
public class Main{
private static Scanner sc;
private static int no_of_videos;
private static String[] S_E;
private static int S;
private static int E;
private static final Map<Integer, Integer> timeSlots = new LinkedHashMap<>();
private static int no_of_groups;
private static int count = 0;
public static void main(String[] args) {
sc = new Scanner(System.in);
no_of_videos = Integer.parseInt(sc.nextLine());
for (int i = 0; i < no_of_videos; i++) {
S_E = sc.nextLine().split(" ");
S = Integer.parseInt(S_E[0]);
E = Integer.parseInt(S_E[1]);
timeSlots.put(S, E);
}
no_of_groups = Integer.parseInt(sc.nextLine());
for (int i = 0; i < no_of_groups; i++) {
String[] split = sc.nextLine().split(" ");
for (int j = 1; j < split.length; j++) {
for (Map.Entry<Integer, Integer> entry : timeSlots.entrySet()) {
Integer starting_time = entry.getKey();
Integer ending_time = entry.getValue();
if (Integer.parseInt(split[j]) >= starting_time && Integer.parseInt(split[j]) < ending_time) {
count++;
}
}
}
System.out.println(count);
count = 0;
}
}
}