title: K Th Distinct Or Non Repeating Element In An Array 1
signature: fun kThDistinctOrNonRepeatingElementInAnArray1(arr: ArrayList<Int>, size: Int, kthindex: Int): Int {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 73, "inputs": {"arr": [17, 25, 27, 27, 73, 91], "size": 5, "kthindex": 3}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [-86, -74, -88, 28, -32, 20, -34, 32], "size": 5, "kthindex": 6}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [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], "size": 33, "kthindex": 32}}, {"idx": 3, "outputs": 6, "inputs": {"arr": [5, 11, 36, 27, 6, 24, 58, 44, 14, 68], "size": 7, "kthindex": 5}}, {"idx": 4, "outputs": -1, "inputs": {"arr": [-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], "size": 27, "kthindex": 27}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [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], "size": 27, "kthindex": 20}}, {"idx": 6, "outputs": 79, "inputs": {"arr": [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], "size": 44, "kthindex": 26}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [-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], "size": 37, "kthindex": 46}}, {"idx": 8, "outputs": -1, "inputs": {"arr": [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], "size": 22, "kthindex": 21}}, {"idx": 9, "outputs": 45, "inputs": {"arr": [1, 23, 75, 84, 28, 34, 15, 13, 51, 69, 94, 45, 38, 38], "size": 13, "kthindex": 12}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, size: Int, kthindex: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, size, kthindex), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(17, 25, 27, 27, 73, 91), 5, 3, 73)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(-86, -74, -88, 28, -32, 20, -34, 32), 5, 6, -1)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(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("TEST-2...${result}")
      
      result = driver(arrayListOf(5, 11, 36, 27, 6, 24, 58, 44, 14, 68), 7, 5, 6)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-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("TEST-4...${result}")
      
      result = driver(arrayListOf(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("TEST-5...${result}")
      
      result = driver(arrayListOf(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("TEST-6...${result}")
      
      result = driver(arrayListOf(-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("TEST-7...${result}")
      
      result = driver(arrayListOf(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("TEST-8...${result}")
      
      result = driver(arrayListOf(1, 23, 75, 84, 28, 34, 15, 13, 51, 69, 94, 45, 38, 38), 13, 12, 45)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: kThDistinctOrNonRepeatingElementInAnArray1
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn