title: K Th Distinct Or Non Repeating Element In An Array 1
signature: def kThDistinctOrNonRepeatingElementInAnArray1(arr: List[Int], size: Int, kthindex: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(arr: List[Int], size: Int, kthindex: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, size, kthindex),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(17, 25, 27, 27, 73, 91), 5, 3, 
        73    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(-86, -74, -88, 28, -32, 20, -34, 32), 5, 6, 
        -1    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(0, 0, 0, 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, 1, 1, 1, 1), 33, 32, 
        -1    
      )}")   
  
  
      println(s"TEST-3...${driver(
        List(5, 11, 36, 27, 6, 24, 58, 44, 14, 68), 7, 5, 
        6    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(-98, -98, -94, -92, -86, -86, -70, -66, -64, -64, -58, -52, -46, -44, -44, -38, -38, -28, -24, -12, -10, -4, -2, 2, 8, 10, 12, 20, 22, 26, 26, 36, 42, 52, 54, 60, 60, 68, 82, 82, 92, 98), 27, 27, 
        -1    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1), 27, 20, 
        -1    
      )}")   
  
  
      println(s"TEST-6...${driver(
        List(3, 8, 9, 10, 10, 13, 14, 16, 18, 23, 24, 25, 27, 28, 30, 33, 36, 39, 42, 42, 44, 45, 45, 48, 52, 52, 55, 55, 59, 59, 59, 60, 61, 61, 66, 66, 67, 68, 71, 72, 75, 76, 79, 80, 94, 94), 44, 26, 
        79    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(-12, 56, -48, 52, -96, -84, 32, -12, -6, 82, 70, 18, 66, -6, -22, -46, -54, 18, -14, -32, 68, 82, -44, -42, 10, 56, 8, -56, 24, 20, -38, 30, -52, -66, 82, -64, 68, -82, 52, -88, -34, -26, 94, 58, -4, -84, -60), 37, 46, 
        -1    
      )}")   
  
  
      println(s"TEST-8...${driver(
        List(0, 0, 0, 0, 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, 1, 1, 1, 1, 1), 22, 21, 
        -1    
      )}")   
  
  
      println(s"TEST-9...${driver(
        List(1, 23, 75, 84, 28, 34, 15, 13, 51, 69, 94, 45, 38, 38), 13, 12, 
        45    
      )}")   
  
  }
  
source_py: def k_th_distinct_or_non_repeating_element_in_an_array_1(arr, size, KthIndex):
      dict = {
          
      }
      vect = []
      for i in range(size):
          if (arr[i] in dict):
              dict[arr[i]] = (dict[arr[i]] + 1)
          else:
              dict[arr[i]] = 1
      for i in range(size):
          if (dict[arr[i]] > 1):
              continue
          else:
              KthIndex = (KthIndex - 1)
          if (KthIndex == 0):
              return arr[i]
      return (- 1)
source_cpp: int k_th_distinct_or_non_repeating_element_in_an_array_1(vector<int> arr, int n, int k) {
    unordered_map < int, int > h;
    for ( int i = 0;
    i < n;
    i ++ ) h [ arr [ i ] ] ++;
    if ( h . size ( ) < k ) return - 1;
    int dist_count = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( h [ arr [ i ] ] == 1 ) dist_count ++;
      if ( dist_count == k ) return arr [ i ];
    }
    return - 1;
  }