Advertisement
Guest User

Untitled

a guest
May 20th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. static int howManyAgentsToAdd(int noOfCurrentAgents, int[][] callsTimes) {
  2. if(callsTimes == null || callTimes.length == 0) return 0;
  3. int n = callsTime.length;
  4. int[] start = new int[n];
  5. int[] end = new int[n];
  6.  
  7. for(int i=0;i<n;i++) {
  8. start[i] = callsTimes[i][0];
  9. end[i] = callsTimes[i][1];
  10. }
  11.  
  12. int ans = maxOverlapIntervalCount( start, end );
  13. return Math.max(0, ans-noOfCurrentAgents);
  14. }
  15. public static int maxOverlapIntervalCount(int[] start, int[] end){
  16. int maxOverlap = 0;
  17. int currentOverlap = 0;
  18.  
  19. Arrays.sort(start);
  20. Arrays.sort(end);
  21.  
  22. int i = 0;
  23. int j = 0;
  24. int m=start.length,n=end.length;
  25. while(i< m && j < n){
  26. if(start[i] < end[j]){
  27. currentOverlap++;
  28. maxOverlap = Math.max(maxOverlap, currentOverlap);
  29. i++;
  30. }
  31. else{
  32. currentOverlap--;
  33. j++;
  34. }
  35. }
  36.  
  37. return maxOverlap;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement