Skip to content

Commit 574716a

Browse files
authored
Create 1744-can-you-eat-your-favorite-candy-on-your-favorite-day.js
1 parent 91cf223 commit 574716a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function canEat(candiesCount: number[], queries: number[][]): boolean[] {
2+
const acc = Array(candiesCount.length);
3+
acc[0] = candiesCount[0];
4+
for (let i = 1; i < candiesCount.length; i++) {
5+
acc[i] = acc[i - 1] + candiesCount[i]
6+
}
7+
8+
return queries.map(([typ, day, cap]) => {
9+
let candyMin = typ === 0 ? 1 : acc[typ - 1] + 1;
10+
let candyMax = acc[typ];
11+
let eatMin = day + 1;
12+
let eatMax = (day + 1) * cap;
13+
return (candyMax < eatMin || eatMax < candyMin) ? false : true;
14+
})
15+
};

0 commit comments

Comments
 (0)