3
2
1
5
6
4
[0][1][2][3][4][5]
Brute force · sort
▸1given arr, k2sort arr ascending3return arr[n − k]
state
- k2
- n6
Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.
Try one problemGiven an integer array and a value k, return the kth largest element by rank in sorted order, which need not be a distinct value.
▸1given arr, k2sort arr ascending3return arr[n − k]
line 1Find the k = 2nd LARGEST value (by rank, not a distinct value). Easiest idea: sort everything, then read off the element k from the end.