public static int findKthSmallest3(int[] arr, int k){
        if(k < 1 || k > arr.length) return -1;
        Comparator<Integer> comparator = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        };

        Queue<Integer> queue = new PriorityQueue<Integer>(k, comparator);
        for(int i = 0; i < k; i++){
            queue.add(arr[i]);
        }

        for(int i = k; i < arr.length; i++){
            if(arr[i] < queue.peek()){
                queue.poll();
                queue.add(arr[i]);
            }
        }
        return queue.poll();
    }