Eating Candies
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
TikTok's August 2024 OA included a candy-eating problem, and it's the kind of trick question that lands hardest when you overthink it. You're probably staring at constraints and edge cases when the actual solution is simpler than it looks. The pattern here lives in greedy logic and simulation. If you blank during the live OA, StealthCoder runs invisible on your screen and surfaces the approach in real time so you don't crater on a solvable problem.
Pattern and pitfall
This problem tests whether you can simulate a process without building unnecessary data structures. The greedy insight is usually about eating candies in the optimal order, or respecting some constraint like eating from both ends or avoiding certain patterns. The trap is overcomplicating it with dynamic programming or recursion when a single pass or two pointers solves it cleanly. Common mistakes: trying to memoize when it's not needed, or misreading the constraint about what happens when you eat. The live OA will have medium test cases that pass a brute-force sim but fail on large inputs, which is where recognizing the greedy or two-pointer pattern becomes your safety net.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Eating Candies cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Eating Candies FAQ
Is this a DP problem or just greedy simulation?+
It reads like DP but it's not. The actual solution is greedy or two-pointer simulation. Build a simple state machine and walk through it once. If you're writing recursive code, you're off the path.
What's the common pitfall candidates hit?+
Overcomplicating the state. Candidates often track too much metadata or try to optimize prematurely. Solve it naively first, then optimize only if test cases fail. Most TikTok OAs reward clarity over cleverness.
Do I need to handle the candies in a specific order?+
Yes, order matters, but not in the way you think. Re-read the constraint carefully. The trick is usually about eating from both ends or respecting a sequence rule. Don't assume you can eat any candy at any time.
How much time should I spend on this if I blank?+
Write a brute-force simulation that passes the examples, even if it's O(n2) or O(n3). Get partial credit. Once it's working, optimize to greedy or two-pointer logic. Don't spend 30 minutes chasing a perfect solution.
Is this problem still asked at TikTok after August 2024?+
Yes. OA problems rotate slowly. If it was in August, it's likely still in the pool through Q4 2024. The pattern won't change, but test case constraints might get stricter, so optimize after you nail the logic.