The Query Kth Smallest Trimmed Number problem gives you an array of equal-length number strings and queries (k, trim). Each query trims each number to its last trim digits and returns the k-th smallest among those trimmed values (using original index for tiebreaking). This coding problem uses multiple sorting approaches including radix sort. The array, sorting, heap, string, and quickselect interview pattern is comprehensively tested.
Goldman Sachs and DE Shaw ask this to test string-based sorting with custom comparators and the ability to choose the right sorting approach (heap for k-th element, radix sort for efficiency). The k-th smallest query maps directly to partial sorting algorithms.
Sort by trimmed suffix + index. For each query (k, trim): extract (trimmed_string, original_index) pairs for all numbers. Sort by (trimmed_string, original_index). Return original_index of the k-th element. Optimize with radix sort for multiple queries on the same trim length.
nums=["102","473","251","814"], queries=[(1,1),(2,3),(4,2)].
Kth Smallest Trimmed Number tests custom comparator sorting. The key: sort by (trimmed_string_lexicographic, original_index). String comparison of zero-padded numbers equals numeric comparison. For multiple queries with the same trim length, batch and reuse sorted order. Practice similar "sort with custom key, find kth element" problems — quickselect or heap are both valid.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Kth Largest Integer in the Array | Medium | Solve | |
| Kth Largest Element in an Array | Medium | Solve | |
| K Closest Points to Origin | Medium | Solve | |
| Top K Frequent Elements | Medium | Solve | |
| Find Kth Largest XOR Coordinate Value | Medium | Solve |