Description
Solutions
Freelancing Platform
🤘 INTERN

A customer has posted several web development projects on a freelancing platform, and various web developers have put in bids for these projects. Given the bid amounts and their corresponding projects, what is the minimum amount the customer can pay to have all projects completed?

Note: If any project has no bids, return -1.

Function Description

Complete the function minCost in the editor.

minCost has the following parameters:

  • int numProjects: the total number of projects posted by the client (labeled from 0 to n-1)
  • int project[n]: the projects that the freelancers bid on
  • int bid[n]: the bid amounts posted by the freelancers
  • Returns

    long: the minimum cost the client can spend to complete all projects, or -1 if any project has no bids.

    ゚⋆ ゚🪐 Credit to chizzy_elect° ᡣ𐭩˚☽˚。⋆

    Example 1:

    Input:  numProjects = 3, project = [2, 0, 1, 2], bid = [8, 7, 6, 9]
    Output: 21
    Explanation:
    There is only one choice of who to hire for project 0, and it will cost 7 :D Likewise, there is only one choice for project 1, which will cost 6 :) For project 2, it is optimal to hire the first web developer, instead of the fourth, and doing so will cost 8 :P So the final answer is 7 + 6 + 8 = 21. If instead there were n = 4 projects, the answer would be -1 since there were no bids received on the fourth project :3

    Example 2:

    Input:  numProjects = 2, project = [0, 1, 0, 1, 1], bid = [4, 74, 47, 744, 7]
    Output: 11
    Explanation:
    The first web developer bid 4 units for project 0 The second web developer bid 74 units for project 1 The third web developer bid 47 units for projevt 0 so on so forth...
    Constraints:
      • 1 ≤ numProjects, n ≤ 5 x 105
      • 0 ≤ project[i] < n
      • 1 ≤ bid[i] ≤ 109
    Thumbnail 0
    Thumbnail 1
    Testcase

    Result
    Case 1

    input:

    output: