static int maxOnesIndex ( boolean arr [ ] , int n ) {
  int i = 0 ;
  int leftCnt = 0 ;
  int rightCnt = 0 ;
  int maxIndex = - 1 ;
  int lastInd = - 1 ;
  int maxCnt = 0 ;
  while ( i < n ) {
    if ( arr [ i ] ) {
      rightCnt ++ ;
    }
    else {
      if ( lastInd != - 1 ) {
        if ( rightCnt + leftCnt + 1 > maxCnt ) {
          maxCnt = leftCnt + rightCnt + 1 ;
          maxIndex = lastInd ;
        }
      }
      lastInd = i ;
      leftCnt = rightCnt ;
      rightCnt = 0 ;
    }
    i ++ ;
  }
  if ( lastInd != - 1 ) {
    if ( leftCnt + rightCnt + 1 > maxCnt ) {
      maxCnt = leftCnt + rightCnt + 1 ;
      maxIndex = lastInd ;
    }
  }
  return maxIndex ;
}

static int maxOnesIndex ( boolean arr [ ] , int n ) { int i = 0 ; int leftCnt = 0 ; int rightCnt = 0 ; int maxIndex = - 1 ; int lastInd = - 1 ; int maxCnt = 0 ; while ( i < n ) { if ( arr [ i ] ) { rightCnt ++ ; } else { if ( lastInd != - 1 ) { if ( rightCnt + leftCnt + 1 > maxCnt ) { maxCnt = leftCnt + rightCnt + 1 ; maxIndex = lastInd ; } } lastInd = i ; leftCnt = rightCnt ; rightCnt = 0 ; } i ++ ; } if ( lastInd != - 1 ) { if ( leftCnt + rightCnt + 1 > maxCnt ) { maxCnt = leftCnt + rightCnt + 1 ; maxIndex = lastInd ; } } return maxIndex ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (boolean_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))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (if_statement condition: (parenthesized_expression (array_access array: (identifier) index: (identifier))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (update_expression (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (return_statement (identifier))))