static int FindSubarray ( int arr [ ] , int n , int k ) {
  int [ ] count_one = new int [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    count_one [ i ] = Integer . bitCount ( arr [ i ] ) ;
  }
  int sum = count_one [ 0 ] ;
  if ( n == 1 ) {
    if ( count_one [ 0 ] >= k ) return 1 ;
    else return - 1 ;
  }
  int ans = Integer . MAX_VALUE ;
  int i = 1 ;
  int j = 0 ;
  while ( i < n ) {
    if ( k == count_one [ j ] ) {
      ans = 1 ;
      break ;
    }
    else if ( k == count_one [ i ] ) {
      ans = 1 ;
      break ;
    }
    else if ( sum + count_one [ i ] < k ) {
      sum += count_one [ i ] ;
      i ++ ;
    }
    else if ( sum + count_one [ i ] > k ) {
      ans = Math . min ( ans , ( i - j ) + 1 ) ;
      sum -= count_one [ j ] ;
      j ++ ;
    }
    else if ( sum + count_one [ i ] == k ) {
      ans = Math . min ( ans , ( i - j ) + 1 ) ;
      sum += count_one [ i ] ;
      i ++ ;
    }
  }
  if ( ans != Integer . MAX_VALUE ) return ans ;
  else return - 1 ;
}

static int FindSubarray ( int arr [ ] , int n , int k ) { int [ ] count_one = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { count_one [ i ] = Integer . bitCount ( arr [ i ] ) ; } int sum = count_one [ 0 ] ; if ( n == 1 ) { if ( count_one [ 0 ] >= k ) return 1 ; else return - 1 ; } int ans = Integer . MAX_VALUE ; int i = 1 ; int j = 0 ; while ( i < n ) { if ( k == count_one [ j ] ) { ans = 1 ; break ; } else if ( k == count_one [ i ] ) { ans = 1 ; break ; } else if ( sum + count_one [ i ] < k ) { sum += count_one [ i ] ; i ++ ; } else if ( sum + count_one [ i ] > k ) { ans = Math . min ( ans , ( i - j ) + 1 ) ; sum -= count_one [ j ] ; j ++ ; } else if ( sum + count_one [ i ] == k ) { ans = Math . min ( ans , ( i - j ) + 1 ) ; sum += count_one [ i ] ; i ++ ; } } if ( ans != Integer . MAX_VALUE ) return ans ; else return - 1 ; }
(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)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) consequence: (return_statement (decimal_integer_literal)) alternative: (return_statement (unary_expression operand: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (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))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (break_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (break_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (identifier))))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) consequence: (return_statement (identifier)) alternative: (return_statement (unary_expression operand: (decimal_integer_literal))))))