Could someone tell me why my solution produces runtime error on the second test case?
*import* java.util.*; *import* java.io.*; *public* *class* ParentingPartnering { *public* *static* *void* main(String [] args) *throws* IOException { Scanner sc = *new* Scanner(*new* BufferedReader(*new* InputStreamReader(System.*in*))); *int* t = sc.nextInt(); *for* (*int* i = 0; i < t; i += 1) { ArrayList<Interval> pts = *new* ArrayList<Interval>(); *int* n = sc.nextInt(); *for* (*int* j = 0; j < n; j += 1) { *int* start = sc.nextInt(); *int* end = sc.nextInt(); Interval s = *new* Interval(*false*, j, start); Interval e = *new* Interval(*true*, j, end); pts.add(s); pts.add(e); } Collections.*sort*(pts); String ans = *solve*(pts, n); System.*out*.println("Case #" + (i + 1) + ": " + ans); } } *static* *class* Interval *implements* Comparable<Interval> { *boolean* isEnd = *false*; *int* id = -1; *int* time = -1; Interval(*boolean* b, *int* i, *int* t) { id = i; isEnd = b; time = t; } @Override *public* *int* compareTo(Interval o) { *if* (*this*.time < o.time) { *return* -1; } *else* *if* (*this*.time == o.time && *this*.isEnd && !o.isEnd) { *return* -1; } *else* { *return* 1; } } } *public* *static* String solve(ArrayList<Interval> lst, *int* n) { *boolean* valid = *isValid*(lst); *char* [] arr = *new* *char*[n]; ArrayList<Character> toUse = *new* ArrayList<Character>(); *if* (valid) { *for* (*int* i = 0; i < lst.size(); i += 1) { Interval p = lst.get(i); *if* (!p.isEnd) { *if* (!toUse.contains('C')) { arr[p.id] = 'C'; toUse.add('C'); } *else* { arr[p.id]= 'J'; toUse.add('J'); } } *else* { toUse.remove((Character) arr[p.id]); } } *return* *new* String(arr); } *else* { *return* "IMPOSSIBLE"; } } *public* *static* *boolean* isValid(ArrayList<Interval> lst) { *int* cnt = 0; *for* (*int* i = 0; i < lst.size(); i += 1) { Interval p = lst.get(i); *if* (!p.isEnd) { cnt += 1; } *else* { cnt -= 1; } *if* (cnt > 2) { *return* *false*; } } *return* *true*; } } Thanks -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/3ea249ea-8eea-47fe-a12a-400c097d6dd5%40googlegroups.com.