Minimize number of boxes by putting small box inside bigger one | Function to minimize the count ; Initial number of box ; Sort array of box size in increasing order ; Check is current box size is smaller than next box size ; Decrement box count Increment current box count Increment next box count ; Check if both box have same size ; Print the result ; Driver code
def minBox ( arr , n ) : NEW_LINE INDENT box = n NEW_LINE arr . sort ( ) NEW_LINE curr_box , next_box = 0 , 1 NEW_LINE while ( curr_box < n and next_box < n ) : NEW_LINE INDENT if ( arr [ curr_box ] < arr [ next_box ] ) : NEW_LINE INDENT box = box - 1 NEW_LINE curr_box = curr_box + 1 NEW_LINE next_box = next_box + 1 NEW_LINE DEDENT elif ( arr [ curr_box ] == arr [ next_box ] ) : NEW_LINE INDENT next_box = next_box + 1 NEW_LINE DEDENT DEDENT print ( box ) NEW_LINE DEDENT size = [ 1 , 2 , 3 ] NEW_LINE n = len ( size ) NEW_LINE minBox ( size , n ) NEW_LINE