GOLDMANSACHS Coding Question – Solved

8 Live
Given a matrix of size m * n, where m denotes the number of rows (starting with index 0) and n denotes the number of columns (starting with index 0), the matrix will hold distinct integers as elements. We need to find the distinct number of positional elements that are either the minimum or maximum in their corresponding row or column. If any row or any column has multiple minimum or maximum elements, return -1. Example: Matrix of size 3 * 3: 1 3 5 8 2 7 4 9 6 The expected output is 7. In this example, we identified the output as 7 based on the following: - 1: Minimum in both its row and column. - 4: Maximum in its row. - 2: Minimum in both its row and column. - 9: Maximum in both its row and column. - 8: Maximum in both its row and column. - 7: Maximum in its column. - 6: Minimum in its row. Thus, the total number of distinct elements that are either the minimum or maximum in their respective row or column is 7. Input: - m: Integer representing the number of rows. - n: Integer representing the number of columns. - matrix: m x n matrix of integers. Output: - r: Integer representing the total number of distinct elements which are either the minimum or maximum in their corresponding row or column. Constraints: - 0 < m, n < 100 - Elements in the matrix are positive integers.

Asked in: GOLDMANSACHS

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



No images available for this passcode.

Solution


Please login to view the solution


Related Questions

| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| Amazon is launching a revolutionary security feature that incorporates an advan… |