Hello Sir can you please review my Code?
============================================

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Solution {
private static boolean isOverLapping(ArrayList<Activity> activityList, 
Activity activity) {
int len = activityList.size();
Activity aux = null;
for (int i = 0; i < len; i++) {
aux = activityList.get(i);
if ((aux.s == activity.s) && (aux.e == activity.e)) {
return true;
}

if ((aux.s <= activity.s) && (aux.e >= activity.e)) {
return true;
}

if ((aux.s <= activity.s) && (aux.e >= activity.e)) {
return true;
}
if ((activity.s <= aux.s) && (activity.e >= aux.e)) {
return true;
}
if (aux.s < activity.s) {
if (aux.e > activity.s) {
return true;
}
}
if (activity.s < aux.s) {
if (activity.e > aux.s) {
return true;
}
}
}
return false;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
int t = Integer.parseInt(br.readLine());
int n = 0, s = 0, e = 0;
String data[] = null;
StringBuilder result = new StringBuilder();
ArrayList<Activity> cameron = new ArrayList<Activity>();
ArrayList<Activity> jamie = new ArrayList<Activity>();
for (int i = 1; i <= t; i++) {
cameron.clear();
jamie.clear();
n = Integer.parseInt(br.readLine());
result = result.delete(0, result.capacity());
for (int j = 0; j < n; j++) {
if (result.toString().trim().equals("IMPOSSIBLE")) {
String aux = br.readLine();
continue;
}
data = br.readLine().split(" ");
s = Integer.parseInt(data[0]);
e = Integer.parseInt(data[1]);
Activity activity = new Activity(s, e);

if (!isOverLapping(cameron, activity)) {
cameron.add(activity);
result.append("C");
} else {
if (!isOverLapping(jamie, activity)) {
jamie.add(activity);
result.append("J");
} else {
result = result.delete(0, result.capacity());
result.append("IMPOSSIBLE");
}
}
}
System.out.println("Case #" + i + ": " + result.toString());
result = result.delete(0, result.capacity());
cameron.clear();
jamie.clear();
}

} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

class Activity {
int s = 0, e = 0;

Activity(int s, int e) {
this.s = s;
this.e = e;
}

public String toString() {
return s + ":" + e;
}
}
==============================================


On Tuesday, April 7, 2020 at 6:36:10 AM UTC+5:30 [email protected] wrote:

> I hope its help,
>
> from functools import reduce
>
> class Solver(object):
>     def __init__(self):
>         super().__init__()
>
>     def find_distribution(self, intervals):
>         _intervals = list(intervals)
>         intervals.sort(key=lambda x: x[0])
>
>         mp = {}
>         J = 0
>         C = 0
>         for e in intervals:
>             tp = (e[0], e[1])
>             if tp not in mp:
>                 mp[tp] = [0]
>             if J <= e[0]:
>                 J = e[1]
>                 mp[tp].append('J')
>                 mp[tp][0] += 1
>             elif C <= e[0]:
>                 C = e[1]
>                 mp[tp].append('C')
>                 mp[tp][0] += 1
>             else:
>                 return 'IMPOSSIBLE' 
>
>         sq = ''
>         for e in _intervals:
>             tp = (e[0], e[1])
>             sq += mp[tp][mp[tp][0]]
>             mp[tp][0] -= 1
>         return sq
>
> def main():
>     solver = Solver()
>     T = int(input())
>     for t in range(T):
>         n = int(input())
>         intervals = []
>         for _ in range(n):
>             intervals.append([int(e) for e in input().split()])
>         print('Case #%d: %s' % (t + 1, 
> solver.find_distribution(intervals))) 
>     return 0
>
> if __name__ == "__main__":
>     main()
>
> On Apr 4, 2020, at 11:54, Martin Seeler <[email protected]> wrote:
>
> I'm asking to keep my sanity: Did anyone solve this problem with Python?
> I can't find these tricky edge cases where my code fails, all variations I 
> try on my machine seem to work just fine. Still CodeJam Environment says 
> *WA*. 
>
> If there is someone who solved it in python, then I know I'm missing some 
> cases. Otherwise I start to question the environment :D
>
> Thanks and have a nice day everyone
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/d7192abb-1170-491e-9ad4-ac0d8f7978c7%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/google-code/d7192abb-1170-491e-9ad4-ac0d8f7978c7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/4b4a5bf2-9006-4bd6-89c6-27846d6a1535%40googlegroups.com.

Reply via email to