List All Permutations of an Alphanumeric String in Digit, Lowercase, Uppercase Order
Company: Wex
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Given a string `s` made of digits, lowercase letters and uppercase letters, return all permutations of `s`, sorted in a custom character order: digits come first, then lowercase letters, then uppercase letters.
### Function Signature
```python
def ordered_permutations(s: str) -> list[str]:
```
### Rules
- A permutation is a string that uses every character of `s` exactly as many times as it appears in `s`, in some order.
- Characters are ranked as follows: every digit ranks below every lowercase letter, and every lowercase letter ranks below every uppercase letter. Within a group the usual order applies: `0` to `9`, `a` to `z`, `A` to `Z`.
- Permutations are ordered by the first position at which they differ, using this rank. All permutations have the same length, so this order is total.
- If `s` contains repeated characters, each distinct permutation appears exactly once.
- This order is not the default string order: in ASCII, uppercase letters sort before lowercase letters.
### Constraints
- `1 <= len(s) <= 8`
- Every character of `s` is in `0-9`, `a-z` or `A-Z`.
- The output has at most `8! = 40,320` strings.
### Examples
**Example 1**
```text
Input: s = "aB1"
Output: ["1aB", "1Ba", "a1B", "aB1", "B1a", "Ba1"]
```
The characters rank `1`, then `a`, then `B`.
**Example 2**
```text
Input: s = "Ab"
Output: ["bA", "Ab"]
```
The lowercase `b` ranks below the uppercase `A`, so `"bA"` comes first, although default string comparison would put `"Ab"` first.
**Example 3**
```text
Input: s = "z0z"
Output: ["0zz", "z0z", "zz0"]
```
The two `z` characters are identical, so there are only three distinct permutations.
Overview: A coding problem that asks for every distinct permutation of a short string of digits, lowercase letters and uppercase letters, returned in a custom order where digits rank first, then lowercase, then uppercase. It tests permutation generation, duplicate handling and ordering that differs from default string comparison.