GOLDMANSACHS Coding Question – Solved

7 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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |