Check if it is possible to rearrange rectangles in a non | Java implementation of above approach ; Function to check if it possible to form rectangles with heights as non - ascending ; set maximum ; replace the maximum with previous maximum ; replace the minimum with previous minimum ; print NO if the above two conditions fail at least once ; Driver code ; initialize the number of rectangles ; initialize n rectangles with length and breadth
import java . io . * ; class GFG { static int rotateRec ( int n , int L [ ] , int B [ ] ) { int m = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . max ( L [ i ] , B [ i ] ) <= m ) m = Math . max ( L [ i ] , B [ i ] ) ; else if ( Math . min ( L [ i ] , B [ i ] ) <= m ) m = Math . min ( L [ i ] , B [ i ] ) ; else { return 0 ; } } return 1 ; } public static void main ( String [ ] args ) { int n = 3 ; int L [ ] = { 5 , 5 , 6 } ; int B [ ] = { 6 , 7 , 8 } ; if ( rotateRec ( n , L , B ) == 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }