title: Count Index Pairs Equal Elements Array 1
signature: class Solution {
  
      public Integer countIndexPairsEqualElementsArray1(ArrayList<Integer> arr, Integer n) {
source_py: def count_index_pairs_equal_elements_array_1(arr, n):
      mp = dict()
      for i in range(n):
          if (arr[i] in mp.keys()):
              mp[arr[i]] += 1
          else:
              mp[arr[i]] = 1
      ans = 0
      for it in mp:
          count = mp[it]
          ans += ((count * (count - 1)) // 2)
      return ans
source_cpp: int count_index_pairs_equal_elements_array_1(vector<int> arr, int n) {
    unordered_map < int, int > mp;
    for ( int i = 0;
    i < n;
    i ++ ) mp [ arr [ i ] ] ++;
    int ans = 0;
    for ( auto it = mp . begin ( );
    it != mp . end ( );
    it ++ ) {
      int count = it -> second;
      ans += ( count * ( count - 1 ) ) / 2;
    }
    return ans;
  }
question_info.extension: java
question_info.entry_fn_name: countIndexPairsEqualElementsArray1
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [5, 11, 18, 22, 40, 46, 50, 51, 53, 55, 64, 67, 73, 78, 86], "n": 14}}, {"idx": 1, "outputs": 2, "inputs": {"arr": [14, -98, 98, 58, -82, 90, -80, -56, -30, -36, -56, -30, -58, 68, 72, -76, 38, -90, -72, 4, -32, 32, -28, 2, 12, -72, 54, 2, 0, -74, 8, 12, 46, 72, -84, -66, 70, 18, 26, 72, -26, 44, -8, 20, -32, -56, 28], "n": 24}}, {"idx": 2, "outputs": 56, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 13}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [93, 23, 62, 64, 31, 78, 99], "n": 4}}, {"idx": 4, "outputs": 4, "inputs": {"arr": [-94, -94, -92, -86, -84, -76, -76, -68, -66, -56, -56, -54, -50, -46, -38, -34, -34, -30, -26, -18, -16, 2, 8, 42, 52, 54, 56, 64, 68, 82, 82, 82, 94, 96, 98], "n": 19}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [0], "n": 0}}, {"idx": 6, "outputs": 2, "inputs": {"arr": [3, 18, 18, 20, 21, 23, 24, 27, 35, 36, 38, 40, 46, 50, 50, 51, 52, 53, 59, 61, 63, 63, 65, 66, 68, 68, 70, 71, 74, 75, 96, 98], "n": 19}}, {"idx": 7, "outputs": 2, "inputs": {"arr": [-68, 40, 16, 50, 36, 42, -20, -46, -92, 4, -18, -12, 48, 0, -46, 64, -74, -50, 42, 44, -56, 28, -10, 78, 62, 70, -60, 12, -44, -78], "n": 23}}, {"idx": 8, "outputs": 211, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 30}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [31, 5], "n": 1}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(5, 11, 18, 22, 40, 46, 50, 51, 53, 55, 64, 67, 73, 78, 86)), 14, 0);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(14, -98, 98, 58, -82, 90, -80, -56, -30, -36, -56, -30, -58, 68, 72, -76, 38, -90, -72, 4, -32, 32, -28, 2, 12, -72, 54, 2, 0, -74, 8, 12, 46, 72, -84, -66, 70, 18, 26, 72, -26, 44, -8, 20, -32, -56, 28)), 24, 2);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 13, 56);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(93, 23, 62, 64, 31, 78, 99)), 4, 0);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-94, -94, -92, -86, -84, -76, -76, -68, -66, -56, -56, -54, -50, -46, -38, -34, -34, -30, -26, -18, -16, 2, 8, 42, 52, 54, 56, 64, 68, 82, 82, 82, 94, 96, 98)), 19, 4);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0)), 0, 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(3, 18, 18, 20, 21, 23, 24, 27, 35, 36, 38, 40, 46, 50, 50, 51, 52, 53, 59, 61, 63, 63, 65, 66, 68, 68, 70, 71, 74, 75, 96, 98)), 19, 2);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-68, 40, 16, 50, 36, 42, -20, -46, -92, 4, -18, -12, 48, 0, -46, 64, -74, -50, 42, 44, -56, 28, -10, 78, 62, 70, -60, 12, -44, -78)), 23, 2);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 30, 211);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(31, 5)), 1, 0);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__