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.
I came up with the similar solution, just code is a bit more compact
static int getMoneySpent(int[] keyboards, int[] drives, int b) {
Arrays.sort(keyboards);
Arrays.sort(drives);
int max = - 1, k = 0;
for (int d = drives.length - 1; d >= 0; d--) {
for (; k < keyboards.length; k++) {
int sum = keyboards[k] + drives[d];
if (sum > b)
break;
max = Math.max(max, sum);
}
}
return max;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
I came up with the similar solution, just code is a bit more compact