Dinkleberg
BAN USER- 0of 2 votes
AnswersGiven a list of pies (and the number of slices in each pie) calculate the maximum number of slices that nPeople could receive if each person got the same amount of slices and did not get slices from more than 1 pie.
- Dinkleberg in United Statespublic int getMaxSlices(List<Integer> pieSlices, int nPeople) { // return answer }
| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm
function isEven(num) {
return num % 2 === 0;
}
What is the question?
- Dinkleberg May 16, 2016This works in O(lg(n)) complexity with the assumption that all prisoners can be bribed for the same value k (k=1).
function findMinCoins(numCells, memo) {
if (numCells < 2) {
return 0;
}
if(memo[numCells]) {
return memo[numCells];
}
var mid = Math.ceil(numCells / 2);
var coins = numCells - 1 + findMinCoins(mid, memo);
if (numCells % 2 === 1) {
coins += findMinCoins(mid, memo);
} else {
coins += findMinCoins(mid - 1, memo); // Even numbers have one less cell on the left
}
memo[numCells] = coins;
return coins;
}
function reverse(str) {
return str.split(' ').reverse().join(' ');
}
I edited such that it says the person cannot take more than one type of pie.
- Dinkleberg May 09, 2016public int[] shuffle(int[] array) {
int randomIndex;
int temp;
for (int i = 0; i < array.length; i++) {
randomIndex = (int) Math.floor(random()*array.length);
temp = array[i];
array[i] = array[randomIndex];
array[randomIndex] = temp;
}
return array;
}
- Dinkleberg May 24, 2016