fork download
  1. class Solution {
  2. public static boolean fun(int[] nums, int mid,int k){
  3. int n=nums.length;
  4. int count=0;
  5.  
  6. for(int i=0;i<n;i++){
  7. if(nums[i] <= mid){
  8. count++;
  9. i++;
  10. }
  11. }
  12. if(count >=k){ //acc to question this is valid
  13. return true;
  14. }
  15. else{
  16. return false;
  17. }
  18. }
  19. public int minCapability(int[] nums, int k) {
  20. int n=nums.length;
  21. //so mid = max
  22. int low =1;
  23. int high =(int)1e9;
  24. int res =(int)1e9;
  25.  
  26. while(low<=high){
  27. int mid=low+(high-low)/2;
  28. if(fun(nums,mid,k)){
  29. res=mid;
  30. high=mid-1;
  31. }
  32. else{
  33. low=mid+1;
  34. }
  35.  
  36. }
  37.  
  38. return res;
  39. }
  40. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
spoj: The program compiled successfully, but main class was not found.
      Main class should contain method: public static void main (String[] args).
stdout
Standard output is empty