TikTok Shop monitors server response times to detect latency regressions. Given an array of latency values and an integer k, return the k-th smallest latency, where k = 1 represents the smallest value.
Use an algorithm that avoids sorting the entire array when k is much smaller than the number of latency measurements.
Implement kth_smallest_latency(latencies, k).
latencies, a non-empty list of integers representing response times in milliseconds, and k, a 1-indexed integer.k - 1 after sorting latencies in ascending order.def kth_smallest_latency(latencies, k):