public static int countOccurence ( int n , int [ ] arr , int k ) {
  int cnt , ans = 0 ;
  HashMap < Integer , Boolean > hash = new HashMap < > ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    cnt = 0 ;
    if ( hash . get ( arr [ i ] ) != null && hash . get ( arr [ i ] ) == true ) continue ;
    hash . put ( arr [ i ] , true ) ;
    for ( int j = i + 1 ;
    j < n ;
    j ++ ) {
      if ( arr [ j ] == arr [ i ] ) cnt ++ ;
      if ( cnt >= k ) break ;
    }
    if ( cnt >= k ) ans ++ ;
  }
  return ans ;
}

public static int countOccurence ( int n , int [ ] arr , int k ) { int cnt , ans = 0 ; HashMap < Integer , Boolean > hash = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { cnt = 0 ; if ( hash . get ( arr [ i ] ) != null && hash . get ( arr [ i ] ) == true ) continue ; hash . put ( arr [ i ] , true ) ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] == arr [ i ] ) cnt ++ ; if ( cnt >= k ) break ; } if ( cnt >= k ) ans ++ ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (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: (identifier) right: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) right: (null_literal)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) right: (true)))) consequence: (continue_statement)) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (true)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (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: (array_access array: (identifier) index: (identifier)))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (break_statement)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (update_expression (identifier)))))) (return_statement (identifier))))