title: First Element Occurring K Times Array
signature: class Solution {
  
      public Integer firstElementOccurringKTimesArray(ArrayList<Integer> arr, Integer n, Integer k) {
source_py: def first_element_occurring_k_times_array(arr, n, k):
      count_map = {
          
      }
      for i in range(0, n):
          if (arr[i] in count_map.keys()):
              count_map[arr[i]] += 1
          else:
              count_map[arr[i]] = 1
          i += 1
      for i in range(0, n):
          if (count_map[arr[i]] == k):
              return arr[i]
          i += 1
      return (- 1)
source_cpp: int first_element_occurring_k_times_array(vector<int> arr, int n, int k) {
    unordered_map < int, int > count_map;
    for ( int i = 0;
    i < n;
    i ++ ) count_map [ arr [ i ] ] ++;
    for ( int i = 0;
    i < n;
    i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ];
    return - 1;
  }
question_info.extension: java
question_info.entry_fn_name: firstElementOccurringKTimesArray
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 4, "inputs": {"arr": [2, 3, 4, 4, 7, 18, 20, 23, 27, 30, 31, 31, 32, 35, 36, 43, 45, 46, 49, 50, 53, 55, 59, 60, 64, 64, 65, 68, 78, 80, 80, 85, 95], "n": 30, "k": 2}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [-26, 32, 36, 6, 64, 24, -28, 96], "n": 6, "k": 3}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 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], "n": 15, "k": 7}}, {"idx": 3, "outputs": 38, "inputs": {"arr": [38, 40, 43, 70, 20, 40, 95, 96, 81, 82], "n": 9, "k": 1}}, {"idx": 4, "outputs": -8, "inputs": {"arr": [-68, -8, -8, 16, 24, 54], "n": 3, "k": 2}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1], "n": 6, "k": 4}}, {"idx": 6, "outputs": 49, "inputs": {"arr": [13, 18, 19, 28, 31, 34, 49, 49, 53, 57, 58, 62, 75, 76, 77, 78, 80, 84, 84, 85, 87, 91, 98, 99], "n": 20, "k": 2}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [-4, 24, -86, -84, 30, -16, 12, -92, -68, 22], "n": 6, "k": 5}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], "n": 8, "k": 10}}, {"idx": 9, "outputs": -1, "inputs": {"arr": [55, 44, 75, 97, 25, 65, 76, 53, 20, 78, 25, 59, 61, 29, 81, 35, 15, 78, 41, 44, 31, 33, 39, 93, 26, 67], "n": 23, "k": 20}}]
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 k, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n, k,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(2, 3, 4, 4, 7, 18, 20, 23, 27, 30, 31, 31, 32, 35, 36, 43, 45, 46, 49, 50, 53, 55, 59, 60, 64, 64, 65, 68, 78, 80, 80, 85, 95)), 30, 2, 4);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-26, 32, 36, 6, 64, 24, -28, 96)), 6, 3, -1);
          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, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 15, 7, -1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(38, 40, 43, 70, 20, 40, 95, 96, 81, 82)), 9, 1, 38);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-68, -8, -8, 16, 24, 54)), 3, 2, -8);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1)), 6, 4, 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(13, 18, 19, 28, 31, 34, 49, 49, 53, 57, 58, 62, 75, 76, 77, 78, 80, 84, 84, 85, 87, 91, 98, 99)), 20, 2, 49);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-4, 24, -86, -84, 30, -16, 12, -92, -68, 22)), 6, 5, -1);
          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, 1, 1, 1, 1)), 8, 10, -1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(55, 44, 75, 97, 25, 65, 76, 53, 20, 78, 25, 59, 61, 29, 81, 35, 15, 78, 41, 44, 31, 33, 39, 93, 26, 67)), 23, 20, -1);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer k, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n, k),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__