FastPrepCount and Score Distinct Hat Assignments
Problems/Count and Score Distinct Hat Assignments

Count and Score Distinct Hat Assignments

Roblox logoRoblox● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report identifies a variant of the people-and-hats assignment problem and adds per-hat points, asking for both the assignment count and the maximum score. The practice contract states the conventional distinct-hat constraint, score indexing, modulo, and impossible sentinel.

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.

More Roblox problems

  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Nov 2026
  • Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public long[] hatAssignmentSummary(int[][] preferences, int[] points) {
        // Write your solution here.
    }
}
Checking account…