FastPrepCount and Score Distinct Hat Assignments

Count and Score Distinct Hat Assignments

Roblox logoRoblox● HardFULLTIMEONSITE INTERVIEW
Learn

Problem statement

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

See Roblox hiring insights
public long[] hatAssignmentSummary(int[][] preferences, int[] points) {
    // Write your solution here.
}
preferences[[1,2],[2,3]]
points[5,7,11]
expected[3,18]
Checking account…