static int minSwaps ( int arr [ ] , int n ) {
  int numberOfOnes = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( arr [ i ] == 1 ) numberOfOnes ++ ;
  }
  int x = numberOfOnes ;
  int count_ones = 0 , maxOnes ;
  for ( int i = 0 ;
  i < x ;
  i ++ ) {
    if ( arr [ i ] == 1 ) count_ones ++ ;
  }
  maxOnes = count_ones ;
  for ( int i = 1 ;
  i <= n - x ;
  i ++ ) {
    if ( arr [ i - 1 ] == 1 ) count_ones -- ;
    if ( arr [ i + x - 1 ] == 1 ) count_ones ++ ;
    if ( maxOnes < count_ones ) maxOnes = count_ones ;
  }
  int numberOfZeroes = x - maxOnes ;
  return numberOfZeroes ;
}

static int minSwaps ( int arr [ ] , int n ) { int numberOfOnes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) numberOfOnes ++ ; } int x = numberOfOnes ; int count_ones = 0 , maxOnes ; for ( int i = 0 ; i < x ; i ++ ) { if ( arr [ i ] == 1 ) count_ones ++ ; } maxOnes = count_ones ; for ( int i = 1 ; i <= n - x ; i ++ ) { if ( arr [ i - 1 ] == 1 ) count_ones -- ; if ( arr [ i + x - 1 ] == 1 ) count_ones ++ ; if ( maxOnes < count_ones ) maxOnes = count_ones ; } int numberOfZeroes = x - maxOnes ; return numberOfZeroes ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (return_statement (identifier))))