Back to questions

Weakest Strong Link Intuit Python Interview Question

Weakest Strong Link

Intuit Python Interview Question

You know that phrase, how a chain is only as strong as its weakest link?

Imagine you had a chain-link fence, represented as a matrix. For the chain-link at position (i, j), the input matrix indicates how strong the chain is at that position (where stronger means a higher number). The numbers in the matrix are unique.

The Weakest Strong Link is defined as the weakest chain-link in its row but also the strongest link in its column.

Given a matrix , return the weakest strong link if it exists; otherwise, return -1. If a weakest strong link exists, it is always exactly one, and it can be proven that no other link will satisfy both conditions simultaneously.

Example #1

Input:
Output:

Explanation:
is the weakest in its row and the strongest in its column , making it the Weakest Strong Link.

Weakest Strong Link Example 1

Example #2

Input:
Output:

Explanation:
No chain-link satisfies the criteria of being the weakest in its row and the strongest in its column.

Input

Python

Output