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

public static int countOccurence ( int n , int [ ] arr , int k ) { int ans = 0 ; HashMap < Integer , Boolean > hash = new HashMap < > ( ) ; HashMap < Integer , Integer > occurence = new HashMap < > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( hash . get ( arr [ i ] ) != null && hash . get ( arr [ i ] ) == true ) continue ; if ( occurence . get ( arr [ i ] ) != null && occurence . get ( arr [ i ] ) >= k ) { ans ++ ; hash . put ( arr [ i ] , true ) ; } else { if ( occurence . get ( arr [ i ] ) == null ) occurence . put ( arr [ i ] , 1 ) ; else { int temp = occurence . get ( arr [ i ] ) ; occurence . put ( arr [ i ] , ++ temp ) ; } } } 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) 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)))) (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (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)) (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: (identifier)))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (true))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))) right: (null_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal)))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (update_expression (identifier))))))))))) (return_statement (identifier))))