text: Removing row or column wise duplicates from matrix of characters | Java code to form string after removing duplicates from rows and columns . ; Function to check duplicates in row and column ; Create an array isPresent and initialize all entries of it as false . The value of isPresent [ i , j ] is going to be true if s [ i , j ] is present in its row or column . ; Checking every row for duplicates of a [ i , j ] ; Checking every column for duplicate characters ; If the character is unique in its row and column ; Driver code ; character array ; Calling function
code: class GFG { static void findDuplciates ( String [ ] a , int n , int m ) { boolean [ ] [ ] isPresent = new boolean [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { isPresent [ i ] [ j ] = false ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( a [ i ] . charAt ( j ) == a [ k ] . charAt ( j ) && i != k ) { isPresent [ i ] [ j ] = true ; isPresent [ k ] [ j ] = true ; } } for ( int k = 0 ; k < m ; k ++ ) { if ( a [ i ] . charAt ( j ) == a [ i ] . charAt ( k ) && j != k ) { isPresent [ i ] [ j ] = true ; isPresent [ i ] [ k ] = true ; } } } } for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( isPresent [ i ] [ j ] == false ) System . out . print ( a [ i ] . charAt ( j ) ) ; } public static void main ( String [ ] args ) { int n = 2 , m = 2 ; String [ ] a = new String [ ] { " zx " , " xz " } ; findDuplciates ( a , n , m ) ; } }