Kth smallest or largest element · Compiler

Kth smallest or largest element

Find the value with rank k in the requested order. SMALL ranks from smallest to largest and LARGE ranks from largest to smallest. Ranks start at 1 and equal values occupy separate positions.

Input
The first line contains n, k, and the word SMALL or LARGE (1 <= k <= n <= 100). The second line contains n space-separated integers from -1000 to 1000.
Output
Print the value at rank k.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…