Reported September 2026
Robloxdynamic programming

Count and Score Distinct Hat Assignments

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

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

Roblox reported this one in September 2026, and the whole solution hinges on a bitmask. With p up to 10 and h up to 40, the trick is to track which people have a hat, not which hats are used. You're staring at an OA invite wondering why a hat problem needs two answers, a count and a max score. It's the classic hat-assignment DP with a scoring twist bolted on. If you blank on the state design mid-assessment, StealthCoder runs invisibly as a safety net and gives you the structure in real time.

The problem

There are p people and h distinct hats numbered from 1 through h. preferences[i] lists the hats person i is willing to wear, and points[j - 1] is the score earned when hat j is assigned.
Assign exactly one preferred hat to every person, and do not assign one hat to two people. Return [ways, maxScore], where ways is the number of valid complete assignments modulo 1,000,000,007, and maxScore is the largest score sum among them. Return [0, -1] when no complete assignment exists.

Function
hatAssignmentSummary(preferences: int[][], points: int[]) → long[]

Examples
Example 1
preferences = [[1,2],[2,3]]
points = [5,7,11]
return = [3,18]
There are three assignments; hats 2 and 3 give the largest score 18.
Example 2
preferences = [[1],[1]]
points = [10]
return = [0,-1]
One hat cannot be assigned to both people.

Constraints
1 <= p <= 10 and 1 <= h <= 40.
points.length = h and 0 <= points[i] <= 10^6.
Every preference list contains distinct hat IDs from 1 through h.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Iterate over hats 1 to h and keep a dp over a bitmask of people already covered, size 2^p. For each hat, either skip it or give it to any person in its list who isn't in the mask yet. Store two values per mask: the number of ways modulo 1,000,000,007 and the max score. Update them together. Ways add up across transitions. Max score takes the best of ways[prev] + points[hat-1]. The common pitfall is masking over hats, which gives 2^40 and dies instantly. Another is applying the modulo to the score. Don't, only the count gets it. Track reachability separately, or use -1 as a sentinel for the max, so unreachable states don't produce fake scores. Final answer is dp[full mask]. If ways is zero, return [0, -1]. Invert preferences into hat to people lists first. Complexity is about h * 2^p * p, which is tiny. StealthCoder is your hedge if the dual-value transition trips you up live.

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 Count and Score Distinct Hat Assignments 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 Roblox's OA.

Roblox 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.

Count and Score Distinct Hat Assignments FAQ

What's the trick for the Roblox hat assignment OA?+

Bitmask over people, not hats. Process hats one at a time and let each hat go to at most one person. The mask has at most 1024 states, so you can afford to loop over all hats and all people per state.

How hard is this really?+

It's a hard-ish DP if you haven't seen the base problem, but easy once you know the mask choice. The score is a small add-on. Most of the difficulty is deciding the state, then keeping count and max in sync.

Should I apply the modulo to the max score?+

No. Only the number of ways takes modulo 1,000,000,007. The max score is a plain sum. Points go up to 10^6 and there are at most 10 people, so it fits comfortably in a long.

How do I handle the no-valid-assignment case?+

Check the count at the full mask. If zero ways reach it, return [0, -1]. Keep unreachable states distinct from reachable ones, with a -1 sentinel or a flag, so a zero score isn't confused with impossible.

How do I prepare for this in 48 hours?+

Write the base hat-counting DP from scratch once, then add the second array for max score. Test on both examples, including the one-hat-two-people case. Practice inverting preferences into hat to people lists, since that's the step people forget.

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

OA at Roblox?
Invisible during screen share
Get it