Trains the technique from
LeetCode 215Kth Largest Element in an ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rooftop weather station writes down how far the temperature moved from one day to the next. swings[i] is the figure recorded on day i in whole degrees, and it runs negative on a day that cooled off.
Line the recorded figures up from highest to lowest and return the figure standing at position k of that line, where position 1 is the highest.
Two days that recorded the same figure each take a place of their own in the line, so a repeated figure occupies several consecutive positions. If four days all recorded 5, then positions 1 through 4 of the line every one of them hold 5. Read the request as a position in that full line, not as a rank among the different figures the station saw: it is the k-th figure counting downward with repeats intact, and asking for the k-th value that differs from the ones above it gives a different, wrong answer.
Arranging the entire log just to read one position off it is more work than the question needs.
Example 1
Highest to lowest the line reads 9, 6, 6, 1, -2, -5. Position 3 holds the second of the two sixes.
Example 2
Three fives fill positions 1, 2 and 3, so position 2 holds 5. Only two figures ever appeared, and treating the request as a rank among them would wrongly report 2.
Example 3
A one-day log leaves a line of length one, and its only entry answers every legal request.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def kth_highest_swing(swings: list[int], k: int) -> int:public int kthHighestSwing(int[] swings, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.