fork(2) 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 void main(String[] args)
  11. {
  12. int arr[] =
  13. {
  14. 40, 30, 35, 60, 80, 100
  15. };
  16. System.out.println(isValid(arr, 0, arr.length, Integer.MIN_VALUE, Integer.MAX_VALUE));
  17. }
  18.  
  19. public static boolean isValid(int arr[], int start, int end, int min, int max)
  20. {
  21. if (end < start || start >= arr.length)
  22. return true;
  23. int root = arr[start];
  24. if (root < min || root > max)
  25. return false;
  26. int i = start + 1;
  27. for (i = start + 1; i < end; i++)
  28. {
  29. if (arr[i] < min || arr[i] > max)
  30. return false;
  31. if (root < arr[i])
  32. break;
  33. }
  34. return isValid(arr, start + 1, i - 1, min, arr[start]) && isValid(arr, i, end, arr[start], max);
  35. }
  36.  
  37. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
true