Reported February 2024
TikTokmath

Stars and Bars

Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live TikTok OA. Under 2s to a working solution.
Founder's read

TikTok's February OA included a combinatorics problem called Stars and Bars. You've got a few hours to nail this. The trick isn't complex math, it's recognizing the pattern: distributing identical items into distinct bins. This is a classic combinatorics setup that looks like a counting problem but actually has a closed-form formula. StealthCoder will help you validate your solution logic in real time if you freeze on the formula during the live OA.

Pattern and pitfall

Stars and Bars is a combinatorics technique for counting the number of ways to distribute n identical objects into k distinct bins. The formula is C(n+k-1, k-1), where C is the binomial coefficient. The problem usually frames it as placing items, distributing resources, or arranging separators. The common pitfall: candidates overthink it and try dynamic programming when the answer is a single binomial calculation. If you see language like 'distribute', 'partition', or 'allocate' with identical units, think combinatorics first. StealthCoder acts as a safety net if the exact formula escapes you under pressure, letting you verify your approach before submitting.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Stars and Bars 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass TikTok's OA.

TikTok reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Stars and Bars FAQ

What's the actual formula for Stars and Bars?+

C(n+k-1, k-1), where n is the number of identical items and k is the number of distinct bins. You're choosing k-1 positions for separators among n+k-1 total positions. That's it. Know this formula cold.

How do I know if a TikTok problem is Stars and Bars?+

Look for language about distributing identical things, partitioning objects into groups, or allocating resources. If the problem says 'identical' or 'indistinguishable' and involves bins or groups, it's a candidate. Non-identical items or constraints often signal DP instead.

Is the answer always just the binomial coefficient?+

Usually yes, but read carefully. Some variants add constraints like 'each bin must have at least one item' (subtracts 1 from n first) or 'at most k items per bin' (harder, often DP). The basic version is always C(n+k-1, k-1).

Do I need to compute the exact binomial or return a modulo value?+

The problem will specify. If large n and k, expect modulo 10^9+7. Use Pascal's triangle, precomputed factorials, or modular inverse for fast computation. Don't try to brute force C(10000, 5000).

What if the problem has constraints or edge cases?+

Zero items, zero bins, or 'at least one per bin' changes the formula. Work through a small example by hand first. If constraints are complex, it might not be pure Stars and Bars, and DP could be safer despite the hint.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with TikTok.

OA at TikTok?
Invisible during screen share
Get it