#1744

Can You Eat Your Favorite Candy on Your Favorite Day?

expert · 1110 · lc medium +32 · verified · 36% accepted · 150 likes · top 14%

Description

You are given candiesCount[i] (count of type-i candies) and queries[i] = [favoriteTypei, favoriteDayi, dailyCapi]. Starting day 0, eat at least 1 candy per day, at most dailyCapi per day on that query, cannot eat type i until all type i-1 are gone. Return a boolean array answer where answer[i] is true if you can eat a type-favoriteTypei candy on day favoriteDayi.

Example 1:

Input: candiesCount = [7,4,5,3,8], queries = [[0,2,2],[4,2,4],[2,13,1000000000]]
Output: [true,false,true]
Explanation:
1- If you eat 2 candies (type 0) on day 0 and 2 candies (type 0) on day 1, you will eat a candy of type 0 on day 2.
2- You can eat at most 4 candies each day.
If you eat 4 candies every day, you will eat 4 candies (type 0) on day 0 and 4 candies (type 0 and type 1) on day 1.
On day 2, you can only eat 4 candies (type 1 and type 2), so you cannot eat a candy of type 4 on day 2.
3- If you eat 1 candy each day, you will eat a candy of type 2 on day 13.

Example 2:

Input: candiesCount = [5,2,6,4,1], queries = [[3,1,2],[4,10,3],[3,10,100],[4,100,30],[1,3,1]]
Output: [false,true,true,false,false]

Code

1
2
3