Find the original matrix when largest element in a row and a column are given | Java implementation of the approach ; Function that prints the original matrix ; Iterate in the row ; Iterate in the column ; If previously existed an element ; Driver code
class GFG { static int N = 3 ; static int M = 7 ; static void printOriginalMatrix ( int a [ ] , int b [ ] , int [ ] [ ] mat ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) System . out . print ( Math . min ( a [ i ] , b [ j ] ) + " ▁ " ) ; else System . out . print ( "0" + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int a [ ] = { 2 , 1 , 3 } ; int b [ ] = { 2 , 3 , 0 , 0 , 2 , 0 , 1 } ; int [ ] [ ] mat = { { 1 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { 1 , 1 , 0 , 0 , 0 , 0 , 0 } } ; printOriginalMatrix ( a , b , mat ) ; } }