title: K Th Distinct Or Non Repeating Element In An Array
signature: int kThDistinctOrNonRepeatingElementInAnArray(vector<int> arr, int n, int k) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int k, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({2, 3, 8, 18, 20, 33, 53, 56, 60, 71, 76, 80, 81, 87, 88, 89, 92, 95}, 16, 16, 89); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-78, 6, 32, 52, -12, -32, 22, -40, -82, 24, 30, 10, -40}, 8, 6, -32); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 7, 5, -1); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({3, 28, 55, 21, 42, 60, 96, 83, 98, 75, 29, 73, 51, 21, 27, 65, 19, 47, 12, 81, 19, 94, 50, 43, 21, 32, 52, 44, 52, 91, 49, 59, 52, 10, 75, 86, 46, 43, 3, 49, 70, 60, 77, 99, 27, 63}, 40, 39, -1); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-96, -90, -76, -44, -16, -8, 0, 0, 2, 2, 8, 14, 16, 18, 18, 20, 20, 28, 34, 44, 68, 74, 84, 90}, 23, 12, 44); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, 10, 8, -1); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({3, 4, 5, 8, 9, 15, 26, 26, 26, 35, 39, 40, 42, 43, 45, 45, 48, 52, 54, 56, 57, 67, 74, 77, 79, 80, 81, 86, 87, 92, 95, 97}, 26, 24, -1); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-76, -24, -12, 66, -40, 26, 72, 46, -56, 58, -68, 2, -82}, 6, 10, -1); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({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, 1, 1, 1, 1}, 27, 17, -1); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({29, 83, 32, 75, 5, 22, 68, 64, 36, 18, 7, 63, 16, 42, 77, 61, 1, 26, 12, 41, 67, 85, 85, 35, 94, 18, 14, 65, 8, 55, 44, 34, 48, 23, 8, 27, 86, 2, 51, 91}, 28, 24, 65); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def k_th_distinct_or_non_repeating_element_in_an_array(arr, n, k):
      dist_count = 0
      for i in range(n):
          j = 0
          while (j < n):
              if ((i != j) and (arr[j] == arr[i])):
                  break
              j += 1
          if (j == n):
              dist_count += 1
          if (dist_count == k):
              return arr[i]
      return (- 1)
source_cpp: int k_th_distinct_or_non_repeating_element_in_an_array(vector<int> arr, int n, int k) {
    int dist_count = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      int j;
      for ( j = 0;
      j < n;
      j ++ ) if ( i != j && arr [ j ] == arr [ i ] ) break;
      if ( j == n ) dist_count ++;
      if ( dist_count == k ) return arr [ i ];
    }
    return - 1;
  }