Rank Fixed-Width Numeric Suffixes with Original-Index Ties
Company: EPAM Systems
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
For each query[k, trim], keep only the rightmost trim digits of every string in `nums`, rank those equal-width numbers increasingly, and return the original index of rank k. Equal trimmed values are ranked by smaller original index. Each query uses the original strings independently; preserve query order.
```cpp
class Solution {
public:
vector<int> smallestTrimmedNumbers(vector<string>& nums, vector<vector<int>>& queries);
};
```
### Examples
**Example 1:**
```text
Input: nums = ["91","21","02"], queries = [[2,1],[1,2]]
Output: [1,2]
Explanation: One-digit values are 1,1,2. The first two tie by original indices 0 then 1, so rank 2 is index 1. At full width, "02" is smallest, at index 2.
```
**Example 2:**
```text
Input: nums = ["007","107"], queries = [[2,2],[1,3]]
Output: [1,0]
Explanation: Both two-digit suffixes are "07", so rank 2 is original index 1. At full width, "007" precedes "107", giving index 0.
```
### Constraints
- `1 <= nums.length, queries.length <= 100`.
- Every digit string has the same length L, with `1 <= L <= 100`; leading zeroes are allowed.
- Every query has two integers, `1 <= k <= nums.length`, `1 <= trim <= L`.
- Original follow-up: use radix sorting.
### Clarifying Questions
- Is `k` one-based? Yes; rank 1 means the smallest value. Returned indices are zero-based.
- What breaks a tie? The smaller original index comes first.
- Does one query permanently change the strings? No; each uses the original strings.
- Are leading zeroes allowed? Yes.
```hint Check the boundary
Check a query whose trimmed values tie but whose original indices differ.
```
Overview: Answer kth-smallest numeric-suffix queries, breaking equal trimmed values by original index and preserving query order.
Rank Fixed-Width Numeric Suffixes with Original-Index Ties
EPAM Systems
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
For each query[k, trim], keep only the rightmost trim digits of every string in nums, rank those equal-width numbers increasingly, and return the original index of rank k. Equal trimmed values are ranked by smaller original index. Each query uses the original strings independently; preserve query order.
class Solution {
public:
vector<int> smallestTrimmedNumbers(vector<string>& nums, vector<vector<int>>& queries);
};
Examples
Example 1:
Input: nums = ["91","21","02"], queries = [[2,1],[1,2]]
Output: [1,2]
Explanation: One-digit values are 1,1,2. The first two tie by original indices 0 then 1, so rank 2 is index 1. At full width, "02" is smallest, at index 2.
Example 2:
Input: nums = ["007","107"], queries = [[2,2],[1,3]]
Output: [1,0]
Explanation: Both two-digit suffixes are "07", so rank 2 is original index 1. At full width, "007" precedes "107", giving index 0.
Constraints
1 <= nums.length, queries.length <= 100
.
Every digit string has the same length L, with
1 <= L <= 100
; leading zeroes are allowed.
Every query has two integers,
1 <= k <= nums.length
,
1 <= trim <= L
.
Original follow-up: use radix sorting.
Clarifying Questions Guidance
Is
k
one-based? Yes; rank 1 means the smallest value. Returned indices are zero-based.
What breaks a tie? The smaller original index comes first.
Does one query permanently change the strings? No; each uses the original strings.