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.
function countApplesAndOranges(s, t, a, b, apples, oranges) {
let landedA = []; // Insertion the final position of all Apples
let landedB = [];// Insertion the final position of all Oranges
for(let i = 0; i < apples.length; i++){
landedA.push(apples[i] + a); // thrown distance + Apple tree position
}
for(let i = 0; i < oranges.length; i++){
landedB.push(oranges[i] + b); // thrown distance + Orange tree position
}
let countApples = 0;
let countOranges = 0;
/* counter for both fruits. If they are between the constraints,
the value is increased by one*/
for(let i = 0; i < landedA.length; i++){
if(landedA[i] >= s && landedA[i] <= t){
countApples++;
}
}
for(let i = 0; i < landedB.length; i++){
if(landedB[i] >= s && landedB[i] <= t){
countOranges++;
}
console.log(countApples);
console.log(countOranges);
}
console.log(countApples);
console.log(countOranges);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →
/Solved in JavaScript (Node.js)/
function countApplesAndOranges(s, t, a, b, apples, oranges) {
}