Problem · Array
Freelancing Platform
Learn this problemProblem statement
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
minCost(numProjects: int, project: int[], bid: int[]) → long
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 onint bid[n]: the bid amounts posted by the freelancersReturns
long: the minimum cost the client can spend to complete all projects, or -1 if any project has no bids.
゚⋆ ゚🪐 Credit to chizzy_elect° ᡣ𐭩˚☽˚。⋆
Examples
Example 1
numProjects = 3project = [2, 0, 1, 2]bid = [8, 7, 6, 9]return = 21There 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
numProjects = 2project = [0, 1, 0, 1, 1]bid = [4, 74, 47, 744, 7]return = 11The 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
More JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Find Total WeightSeen Jun 2025