Number of visible boxes after putting one inside another | C # program to count number of visible boxes . ; return the minimum number of visible boxes ; New Queue of integers . ; sorting the array ; traversing the array ; checking if current element is greater than or equal to twice of front element ; Pushing each element of array ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int minimumBox ( int [ ] arr , int n ) { Queue < int > q = new Queue < int > ( ) ; Array . Sort ( arr ) ; q . Enqueue ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { int now = q . Peek ( ) ; if ( arr [ i ] >= 2 * now ) q . Dequeue ( ) ; q . Enqueue ( arr [ i ] ) ; } return q . Count ; } public static void Main ( ) { int [ ] arr = { 4 , 1 , 2 , 8 } ; int n = arr . Length ; Console . WriteLine ( minimumBox ( arr , n ) ) ; } }