You are given a permutation of integers from 1 to n stored in an array arr, and an integer k. The ith greatest element of an array is the ith element when sorted in decreasing order.
For each prefix of the array of length i (where i ranges from k to n), find the kth greatest element.
n = 4 k = 2 arr = [4, 2, 1, 3]
Find the 2nd greatest element for each prefix of size i ≥ k:
Return the array [2, 2, 3].