FastPrepMinimum Project Bid Cost

Minimum Project Bid Cost

NVIDIA logoNVIDIA● EasyINTERNNEW GRADOA

Problem statement

There are numProjects projects numbered from 0 to numProjects - 1. Two arrays describe the submitted bids: bid i offers to complete project projectId[i] for a cost of bid[i].

Choose one bid for every project to minimize the total cost. Each bid applies only to its listed project, and choices for different projects are independent.

Return the minimum total cost. If any project has no bid, return -1.

Function

minimumProjectBidCost(numProjects: int, projectId: int[], bid: int[]) → long

Examples

Example 1

numProjects = 3projectId = [0,1,0,2,1]bid = [8,5,3,7,9]return = 15

The lowest bids for projects 0, 1, and 2 are 3, 5, and 7. Their total is 15.

Example 2

numProjects = 3projectId = [0,2,0]bid = [4,6,2]return = -1

Project 1 has no bid, so it is impossible to cover every project. Return -1.

Example 3

numProjects = 2projectId = [1,0,1]bid = [0,9,4]return = 9

Choose the bid of 9 for project 0 and the bid of 0 for project 1. The total is 9.

Constraints

  • 1 <= numProjects <= 10^5
  • 0 <= projectId.length <= 10^5
  • projectId.length == bid.length
  • 0 <= projectId[i] < numProjects
  • 0 <= bid[i] <= 10^9

More NVIDIA problems

See NVIDIA hiring insights
Saved
public long minimumProjectBidCost(int numProjects, int[] projectId, int[] bid) {
    // Write your code here.
}
numProjects3
projectId[0,1,0,2,1]
bid[8,5,3,7,9]
expected15
Checking account…