fork download
  1. class Solution {
  2. public static boolean mm(int[]nums,int p,int mid){
  3.  
  4. int n=nums.length;
  5. int count=0;
  6. for(int i=1;i<n;i++){
  7. if(Math.abs(nums[i]-nums[i-1]) <= mid){
  8. count++;
  9. i++;
  10. }
  11. }
  12. if(count >=p){
  13. return true;
  14. }
  15. else{
  16. return false;
  17. }
  18. }
  19. public int minimizeMax(int[] nums, int p) {
  20. int n=nums.length;
  21.  
  22. int res=0;
  23.  
  24. Arrays.sort(nums);
  25. int low=0;
  26. int high =(int)1e9;
  27.  
  28. while(low<=high){
  29. int mid=low+(high-low)/2;//mid gives max difference possible
  30. if(mm(nums,p,mid)){
  31. res=mid;
  32. high=mid-1;
  33. }
  34. else{
  35. low=mid+1;
  36. }
  37.  
  38. }
  39. return res;
  40. }
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:24: error: cannot find symbol
        Arrays.sort(nums);
        ^
  symbol:   variable Arrays
  location: class Solution
1 error
stdout
Standard output is empty