fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int countBalloon(int [][] arr){
  11. int len = arr.length;
  12. int first = 0;
  13. int second = 1;
  14. int count = 0;
  15. while(second < len){
  16. if(arr[first][1] >= arr[second][0]){
  17. second++;
  18. } else{
  19. count++;
  20. first++;
  21. second++;
  22. }
  23. }
  24. count++;
  25. return count;
  26. }
  27.  
  28. public static void main (String[] args) throws java.lang.Exception
  29. {
  30. int[][] arr = new int[4][2];
  31. arr[0][0] = 1;
  32. arr[0][1] = 2;
  33. arr[1][0] = 3;
  34. arr[1][1] = 4;
  35. arr[2][0] = 5;
  36. arr[2][1] = 6;
  37. arr[3][0] = 7;
  38. arr[3][1] = 8;
  39. System.out.println(Ideone.countBalloon(arr));
  40. }
  41. }
Success #stdin #stdout 0.08s 46740KB
stdin
Standard input is empty
stdout
4