Tap here to switch tabs
Problem
Submissions

Problem: Query Kth Smallest Trimmed Number

med
30 min
Try to solve the Query Kth Smallest Trimmed Number problem.

Statement

You are given an array of strings nums, where each string consists of digits and all strings have the same length. You are also given a 22D integer array queries, where queries[i] = [ k_i , trim_i ].

For each query:

  1. Trim each number in nums to its rightmost trim_i digits.

  2. Find the original index of the kiextthk_i^{ ext{th}} smallest trimmed number. If two trimmed values are equal, the element with the smaller index in nums is considered smaller.

  3. Reset each number in nums to its initial length before processing the next query.

Return an array of integers representing the answers to each query in order.

Note: Trimmed numbers with leading zeros are still evaluated based on their numerical value. Since all trimmed strings for a query have the exact same length of trim_i digits, their numerical comparison is identical to their lexicographical comparison.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i].length ≤100\leq 100

  • nums[i] consists of only digits.

  • All nums[i].length are equal.

  • 1≤1 \leq queries.length ≤100\leq 100

  • queries[i].length =2= 2

  • 1≤1 \leq k_i ≤\leq nums.length

  • 1≤1 \leq trim_i ≤\leq nums[i].length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Query Kth Smallest Trimmed Number

med
30 min
Try to solve the Query Kth Smallest Trimmed Number problem.

Statement

You are given an array of strings nums, where each string consists of digits and all strings have the same length. You are also given a 22D integer array queries, where queries[i] = [ k_i , trim_i ].

For each query:

  1. Trim each number in nums to its rightmost trim_i digits.

  2. Find the original index of the kiextthk_i^{ ext{th}} smallest trimmed number. If two trimmed values are equal, the element with the smaller index in nums is considered smaller.

  3. Reset each number in nums to its initial length before processing the next query.

Return an array of integers representing the answers to each query in order.

Note: Trimmed numbers with leading zeros are still evaluated based on their numerical value. Since all trimmed strings for a query have the exact same length of trim_i digits, their numerical comparison is identical to their lexicographical comparison.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i].length ≤100\leq 100

  • nums[i] consists of only digits.

  • All nums[i].length are equal.

  • 1≤1 \leq queries.length ≤100\leq 100

  • queries[i].length =2= 2

  • 1≤1 \leq k_i ≤\leq nums.length

  • 1≤1 \leq trim_i ≤\leq nums[i].length