Skip to the code
cf.
+25 XP

#557 Assign Reviewers at Least Cost

medium

A team has n reviewers and n open pull requests. cost[r][p] is how many hours reviewer r needs to review pull request p. Each reviewer gets exactly one pull request, and each pull request gets exactly one reviewer.

Write assignReviewers(cost) that returns the smallest total number of hours.

Example 1

Input: cost = [[9,2,7],[6,4,3],[5,8,1]]
Output: 9

Reviewer 0 takes PR 1 (2), reviewer 1 takes PR 0 (6), reviewer 2 takes PR 2 (1).

Example 2

Input: cost = [[5]]
Output: 5

One reviewer, one pull request.

Constraints

  • 1 <= n <= 15
  • cost.length === n and every row has length n
  • 0 <= cost[r][p] <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).