CJCoding With Joseph
15free / daySign inCreate account

Kth Smallest Value

Write kth_smallest(values: list[int], k: int) -> int that returns the k-th smallest value counting from 1, so a k of 1 gives the minimum. Sort a copy with sorted(), because the original list must stay untouched, and index the copy at k - 1. k is always between 1 and the length of the list. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, a space-separated list of integers and then k; the tests print the value your function returns and then the original list, to show it was not reordered.

Expected Output:

4
[7, 2, 9, 4]

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
7 2 9 4\n2\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.