title: K Th Distinct Or Non Repeating Element In An Array 1
signature: k_th_distinct_or_non_repeating_element_in_an_array_1 <- function(arr, size, kthindex) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, size, kthindex, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, size, kthindex), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(17L, 25L, 27L, 27L, 73L, 91L), 5L, 3L, 
          73L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-86L, -74L, -88L, 28L, -32L, 20L, -34L, 32L), 5L, 6L, 
          -1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 33L, 32L, 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(5L, 11L, 36L, 27L, 6L, 24L, 58L, 44L, 14L, 68L), 7L, 5L, 
          6L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -98L, -94L, -92L, -86L, -86L, -70L, -66L, -64L, -64L, -58L, -52L, -46L, -44L, -44L, -38L, -38L, -28L, -24L, -12L, -10L, -4L, -2L, 2L, 8L, 10L, 12L, 20L, 22L, 26L, 26L, 36L, 42L, 52L, 54L, 60L, 60L, 68L, 82L, 82L, 92L, 98L), 27L, 27L, 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L), 27L, 20L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 8L, 9L, 10L, 10L, 13L, 14L, 16L, 18L, 23L, 24L, 25L, 27L, 28L, 30L, 33L, 36L, 39L, 42L, 42L, 44L, 45L, 45L, 48L, 52L, 52L, 55L, 55L, 59L, 59L, 59L, 60L, 61L, 61L, 66L, 66L, 67L, 68L, 71L, 72L, 75L, 76L, 79L, 80L, 94L, 94L), 44L, 26L, 
          79L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-12L, 56L, -48L, 52L, -96L, -84L, 32L, -12L, -6L, 82L, 70L, 18L, 66L, -6L, -22L, -46L, -54L, 18L, -14L, -32L, 68L, 82L, -44L, -42L, 10L, 56L, 8L, -56L, 24L, 20L, -38L, 30L, -52L, -66L, 82L, -64L, 68L, -82L, 52L, -88L, -34L, -26L, 94L, 58L, -4L, -84L, -60L), 37L, 46L, 
          -1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 22L, 21L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(1L, 23L, 75L, 84L, 28L, 34L, 15L, 13L, 51L, 69L, 94L, 45L, 38L, 38L), 13L, 12L, 
          45L
      )))
  
  }
  
  main()
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;
  }