Largest Number
Real-world version: Greatest Shipment TagThe statement here is our own: the same inputs, outputs and technique.
A packing station prints the part number of every item in a shipment on its own slip, then glues the slips into one row that reads as a single numeral: the shipment tag. The station picks the order of the slips, and each slip is used exactly once with its digits kept as printed.
Given the part numbers parts, return the greatest tag the station can glue, as a string. A tag is never printed with a leading zero, so when every part number is 0 the tag reads "0". The answer comes back as a string because a tag can run far past what a machine integer holds.
Examples
Example 1
- Input
- parts = [7, 70]
- Output
- "770"
Gluing 7 in front gives 770, while 70 in front gives 707, so 7 leads.
Example 2
- Input
- parts = [2, 25, 251]
- Output
- "252512"
The order 25, 251, 2 reads as 252512, which beats every other arrangement, including 251 first at 251252.
Example 3
- Input
- parts = [2, 10, 0]
- Output
- "2100"
2 leads, then 10, then 0; putting 0 anywhere earlier only shrinks the tag.
Constraints
- 1 <= parts.length <= 100
- 0 <= parts[i] <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def greatest_tag(parts: list[int]) -> str:public String greatestTag(int[] parts)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's