tomtom's note: Not entirely sure if this question is from TikTok, but I included it in the collection just in case :))
There are n
candies put from left to right on a table. The candies are numbered from left to right. The i-th candy has weight wi
. Alice and Bob eat candies.
Alice can eat any number of candies from the left (she can't skip candies, she eats them in a row).
Bob can eat any number of candies from the right (he can't skip candies, he eats them in a row).
Of course, if Alice ate a candy, Bob can't eat it (and vice versa).
They want to be fair. Their goal is to eat the same total weight of candies. What is the most number of candies they can eat in total?
Example 1:
Input: candies = [1000]
Output: 0
Explanation:There is only one candy, and it is not possible for Alice and Bob to eat the same total weight. So the function should return 0.
Example 2:
Input: candies = [1, 2, 1]
Output: 2
Explanation:Alice takes 1 candy from the left, and Bob takes 1 candy from the right. So the function should return 2.
🐻❄️

input:
output: