//sample solution
function appleBoxes(k) {
var yellowAppleSum = 0;
var redAppleSum = 0;
for(i=1;i<=k;i++){
if(i%2==0){ //even
redAppleSum = redAppleSum + (i*i);
} else { //odd
if(i>1){
yellowAppleSum = yellowAppleSum + (i*i);
} else {
yellowAppleSum = yellowAppleSum + 1;
}
}
}
return (redAppleSum - yellowAppleSum);
}
No comments:
Post a Comment