Maximum-Weight Bipartite Matching
Updated
Problem statement
A rectangular matrix weights describes a bipartite graph. Row i is a left vertex and column j is a right vertex. A non-negative entry is the weight of edge (i,j); -1 means the edge is absent.
Choose edges of maximum total weight so that no vertex is used more than once. Vertices may remain unmatched. Return the maximum total weight as a signed 64-bit integer.
Function
maximumMatchingWeight(weights: int[][]) → longExamples
Example 1
weights = [[5,1],[4,7]]return = 12Match row 0 to column 0 and row 1 to column 1.
Example 2
weights = [[9,8,7],[6,-1,5]]return = 14Choose weights 8 and 6 using distinct columns.
Example 3
weights = [[-1,-1],[3,-1]]return = 3Only one available edge is useful; the other row stays unmatched.
Constraints
0 <= rows <= 50.0 <= columns <= 15.- Every entry is
-1or lies in[0,10^9].
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Minimum Semesters With Course CapacityAmazon · ONSITE INTERVIEW
- Shortest Path Visiting All NodesInMobi · ONSITE INTERVIEWInMobi interview questions
- Minimum Distance Matching in a ForestScale AI · PHONE SCREEN · ONSITE INTERVIEWScale AI interview questions
- Longest Anchored Song ChainIntuit · OAIntuit interview questions
- Cheapest Visiting Order with PrerequisitesIndeed · OAIndeed interview questions
- Minimum Semesters with a Course LimitSnowflake · PHONE SCREENSnowflake interview questions
- Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
- Minimum Traveling Salesperson TourGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Grid Robot Route with Charging PrioritiesUber · PHONE SCREEN · ONSITE INTERVIEWUber interview questions