title: Number Visible Boxes Putting One Inside Another
signature: number_visible_boxes_putting_one_inside_another <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 3L, 17L, 17L, 18L, 28L, 28L, 29L, 34L, 43L, 44L, 52L, 54L, 80L, 84L, 84L, 91L, 92L, 97L), 12L, 
          7L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-94L, -90L, -90L, -78L, -34L, -26L, -10L, 4L, 24L, 28L, 64L, 70L, 72L, 74L, 80L, 82L), 10L, 
          2L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 40L, 
          15L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(2L, 3L, 5L, 8L, 12L, 16L, 20L, 30L, 37L, 53L, 55L, 62L, 76L, 81L, 83L, 87L, 88L, 96L), 9L, 
          3L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -92L, -60L, -58L, -54L, -42L, -36L, -12L, -8L, -2L, 8L, 14L, 18L, 20L, 26L, 32L, 38L, 56L, 58L, 60L, 70L, 78L, 80L, 86L, 98L), 18L, 
          4L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 9L, 
          4L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(1L, 1L, 2L, 3L, 3L, 11L, 16L, 18L, 19L, 21L, 21L, 22L, 22L, 24L, 27L, 28L, 29L, 43L, 43L, 52L, 55L, 57L, 60L, 62L, 62L, 63L, 65L, 66L, 70L, 70L, 73L, 77L, 78L, 79L, 79L, 80L, 85L, 85L, 86L, 88L, 89L, 90L, 97L, 98L), 30L, 
          13L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-94L, -82L, -80L, -78L, -68L, -60L, -58L, -44L, -44L, -42L, -30L, -30L, -22L, -18L, -18L, -14L, -14L, -10L, -8L, -6L, 4L, 4L, 6L, 12L, 12L, 14L, 18L, 30L, 44L, 48L, 50L, 52L, 54L, 80L, 86L, 88L, 88L), 21L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, 
          3L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(3L, 5L, 5L, 10L, 12L, 16L, 22L, 31L, 31L, 32L, 39L, 43L, 43L, 47L, 49L, 50L, 51L, 52L, 52L, 56L, 59L, 59L, 62L, 69L, 69L, 71L, 75L, 81L, 82L, 83L, 83L, 86L, 89L, 90L, 90L, 96L), 28L, 
          17L
      )))
  
  }
  
  main()
source_py: def number_visible_boxes_putting_one_inside_another(arr, n):
      q = collections.deque([])
      arr.sort()
      q.append(arr[0])
      for i in range(1, n):
          now = q[0]
          if (arr[i] >= (2 * now)):
              q.popleft()
          q.append(arr[i])
      return len(q)
source_cpp: int number_visible_boxes_putting_one_inside_another(vector<int> arr, int n) {
    queue < int > q;
    sort(arr.begin(), arr.end());
    q . push ( arr [ 0 ] );
    for ( int i = 1;
    i < n;
    i ++ ) {
      int now = q . front ( );
      if ( arr [ i ] >= 2 * now ) q . pop ( );
      q . push ( arr [ i ] );
    }
    return q . size ( );
  }