Check if a grid can become row | v [ ] is vector of strings . len is length of strings in every row . ; Driver code ; let len = 5 ; Length of strings
function check ( v , len ) { let n = v . length ; let tempArray ; for ( let i = 0 ; i < n ; i ++ ) { tempArray = v [ i ] . split ( " " ) ; ( tempArray ) . sort ( ) ; v [ i ] = ( tempArray ) . join ( " " ) ; } for ( let i = 0 ; i < len - 1 ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) if ( v [ i ] [ j ] > v [ i + 1 ] [ j ] ) return false ; return true ; } let v = [ " " , " " , " " , " " , " " ] ; if ( check ( v , len ) ) document . write ( " " ) ; else document . write ( " " ) ;