Problem · Array
Eating Candies
Learn this problemProblem statement
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?
Function
mostCandiesEaten(candies: int[]) → intExamples
Example 1
candies = [1000]return = 0There 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
candies = [1, 2, 1]return = 2Alice takes 1 candy from the left, and Bob takes 1 candy from the right.
So the function should return 2.
Constraints
🐻❄️More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026