NewThe Learning module is now liveSee what's new

(This question is a variation of the LeetCode question 703. Kth Largest Element in a Stream. If you haven't completed that question yet, it is recommended to solve it first.)

You are given a permutation arr of the integers from 1 to n (each integer appears exactly once), and an integer k. For each prefix of arr of length i, where i ranges [k, n] inclusive, find the kthk^{\text{th}} greatest element among the first i elements.

Test Cases
Input
Output
Expected