title: K Th Distinct Or Non Repeating Element In An Array 1
signature: function kThDistinctOrNonRepeatingElementInAnArray1(arr, size, kthindex) {
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;
  }