- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find a matrix for each condominium's height is increased to the maximum possible height in Python?

Suppose we have a 2D matrix, where matrix [r, c] represents the height of a condominium in a city. The west-east skyline is visible by taking the maximum of each row in the matrix. And the north-south skyline can be visible by taking the maximum of each column. We have to find a new matrix where each condominium's height is increased to the maximum possible height while keeping the same west-east and north-south skyline.

So, if the input is like

2 | 3 | 4 |

5 | 6 | 7 |

8 | 9 | 10 |

4 | 4 | 4 |

7 | 7 | 7 |

8 | 9 | 10 |

as the west-east skyline is [4, 7, 10] and north-south skyline is [8, 9, 10]. We can increase everything in the first row to value 4 and everything in the second row to value 7 without changing the skylines.

To solve this, we will follow these steps:

r := a list of maximum of each row in the matrix

c := a list of maximum of each column in the matrix

for i in range 0 to row count of matrix, do

for j in range 0 to column count of matrix, do

if r[i] < c[j], then

matrix[i, j] := r[i]

otherwise,

matrix[i, j] := c[j]

return matrix

Let us see the following implementation to get better understanding:

## Example

class Solution: def solve(self, matrix): r = [max(i) for i in matrix] c = [max(i) for i in zip(*matrix)] for i in range(len(matrix)): for j in range(len(matrix[i])): if r[i] < c[j]: matrix[i][j] = r[i] else: matrix[i][j] = c[j] return matrix ob = Solution() matrix = [ [2, 3, 4], [5, 6, 7], [8, 9, 10] ] print(ob.solve(matrix))

## Input

[[2, 3, 4], [5, 6, 7], [8, 9, 10]]

## Output

[[4, 4, 4], [7, 7, 7], [8, 9, 10]]

- Related Questions & Answers
- Program to find maximum building height in Python
- Python Program for Maximum height when coins are arranged in a triangle
- Write a Program to Find the Maximum Depth or Height of a Tree in C++
- Python Program to Read Height in Centimeters and convert the Height to Feet and Inches
- Program to find maximum XOR for each query in Python
- Python program to find the redundancy rates for each row of a matrix
- What is the difference between height and line-height?
- C/C++ Program for Maximum height when coins are arranged in a triangle?
- How to find the maximum value for each column of a matrix in R?
- C++ program to find maximum possible value for which XORed sum is maximum
- C++ program to find maximum possible median of elements whose sum is s
- Height Checker in Python
- Java Program to increase the row height in a JTable
- Find maximum height pyramid from the given array of objects in C++
- C++ program to find out the center coordinates and the height of a building