Trains the technique from
LeetCode 2343Query Kth Smallest Trimmed NumberThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A batch of serials is given as nums, each a string of digits, and all of them the same length.
Each query queries[j] = [k, trim] asks you to keep only the rightmost trim digits of every serial, then find the k-th smallest of those trimmed serials, counting from 1. Trimmed serials are compared as text, so leading zeros count, and when two are equal the one whose original serial appears earlier in nums is treated as smaller.
Return an array answer where answer[j] is the position in nums of the serial the j-th query picks out. Queries are independent and never change nums.
Example 1
Keeping one digit gives "2", "3", "1", "4", whose smallest is at position 2. Keeping three digits leaves the serials whole, and the second smallest of those is at position 2 as well.
Example 2
Keeping two digits gives "19" for all three serials, so the tie is settled by the order they appear in.
Example 3
Compared as text, "01" comes before "10", so the first query picks position 1 and the second picks position 0.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def kth_by_tail(nums: list[str], queries: list[list[int]]) -> list[int]:public int[] kthByTail(List<String> nums, int[][] queries)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.