title: K Th Distinct Or Non Repeating Element In An Array
signature: k_th_distinct_or_non_repeating_element_in_an_array <- function(arr, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 3L, 8L, 18L, 20L, 33L, 53L, 56L, 60L, 71L, 76L, 80L, 81L, 87L, 88L, 89L, 92L, 95L), 16L, 16L, 
          89L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-78L, 6L, 32L, 52L, -12L, -32L, 22L, -40L, -82L, 24L, 30L, 10L, -40L), 8L, 6L, 
          -32L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, 5L, 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(3L, 28L, 55L, 21L, 42L, 60L, 96L, 83L, 98L, 75L, 29L, 73L, 51L, 21L, 27L, 65L, 19L, 47L, 12L, 81L, 19L, 94L, 50L, 43L, 21L, 32L, 52L, 44L, 52L, 91L, 49L, 59L, 52L, 10L, 75L, 86L, 46L, 43L, 3L, 49L, 70L, 60L, 77L, 99L, 27L, 63L), 40L, 39L, 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -90L, -76L, -44L, -16L, -8L, 0L, 0L, 2L, 2L, 8L, 14L, 16L, 18L, 18L, 20L, 20L, 28L, 34L, 44L, 68L, 74L, 84L, 90L), 23L, 12L, 
          44L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L), 10L, 8L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 4L, 5L, 8L, 9L, 15L, 26L, 26L, 26L, 35L, 39L, 40L, 42L, 43L, 45L, 45L, 48L, 52L, 54L, 56L, 57L, 67L, 74L, 77L, 79L, 80L, 81L, 86L, 87L, 92L, 95L, 97L), 26L, 24L, 
          -1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-76L, -24L, -12L, 66L, -40L, 26L, 72L, 46L, -56L, 58L, -68L, 2L, -82L), 6L, 10L, 
          -1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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, 1L, 1L, 1L, 1L), 27L, 17L, 
          -1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(29L, 83L, 32L, 75L, 5L, 22L, 68L, 64L, 36L, 18L, 7L, 63L, 16L, 42L, 77L, 61L, 1L, 26L, 12L, 41L, 67L, 85L, 85L, 35L, 94L, 18L, 14L, 65L, 8L, 55L, 44L, 34L, 48L, 23L, 8L, 27L, 86L, 2L, 51L, 91L), 28L, 24L, 
          65L
      )))
  
  }
  
  main()
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;
  }