title: First Element Occurring K Times Array
signature: class Solution {
  
      public int FirstElementOccurringKTimesArray(List<int> arr, int n, int k) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int k, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n, k); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-26, 32, 36, 6, 64, 24, -28, 96}, 6, 3, 
                  -1
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{38, 40, 43, 70, 20, 40, 95, 96, 81, 82}, 9, 1, 
                  38
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-68, -8, -8, 16, 24, 54}, 3, 2, 
                  -8
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, 6, 4, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-4, 24, -86, -84, 30, -16, 12, -92, -68, 22}, 6, 5, 
                  -1
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 8, 10, 
                  -1
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }