We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is my solution for java 8
public static int maxMin(int k, List arr) {
// Write your code here
int result = 99999999;
Collections.sort(arr);
int lastindex = k-1;
for (int i=0;i
}
Just out of curiosity, is there a way to solve this problem without using sorting? This might be helpful if e.g. you do not have an access to the sorting functions
function maxMin(k, arr) {
arr.sort((a,b)=>a-b);
let l = arr.length, u = arr[l-1] - arr[l-k];
for(let i = 0;i<=(arr.length-k);i++){
let t = arr[i+(k-1)] - arr[i];
u = t <= u ? t: u;
}
return u;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java
this is my solution for java 8 public static int maxMin(int k, List arr) { // Write your code here int result = 99999999; Collections.sort(arr); int lastindex = k-1; for (int i=0;i }
Just out of curiosity, is there a way to solve this problem without using sorting? This might be helpful if e.g. you do not have an access to the sorting functions
//JavaScript Code
}