Choose a random pivot for the list. We can use a more sophisticated algorithm here, such as the median-of-medians algorithm.
(lst)
| 15 | |
| 16 | |
| 17 | def random_pivot(lst): |
| 18 | """ |
| 19 | Choose a random pivot for the list. |
| 20 | We can use a more sophisticated algorithm here, such as the median-of-medians |
| 21 | algorithm. |
| 22 | """ |
| 23 | return choice(lst) |
| 24 | |
| 25 | |
| 26 | def kth_number(lst: list[int], k: int) -> int: |