Excel Sheet Column Title
Real-world version: Seed Tray LabelThe statement here is our own: the same inputs, outputs and technique.
A seed bank stencils a label on every cold-storage tray. Labels use nothing but the 26 capital letters A through Z, and the bank hands them out in a fixed order: all the one-letter labels first, in alphabetical order, then all the two-letter labels in dictionary order, then all the three-letter labels, and so on without end.
So the first tray installed is stencilled "A", the twenty-sixth "Z", the twenty-seventh "AA", the twenty-eighth "AB", and after "AZ" comes "BA".
Given columnNumber, the position of a tray in that installation order, return the label stencilled on it.
Examples
Example 1
- Input
- columnNumber = 27
- Output
- "AA"
The 26 one-letter labels are used up by tray 26, so tray 27 gets the first two-letter label in dictionary order.
Example 2
- Input
- columnNumber = 26
- Output
- "Z"
Tray 26 is still inside the run of one-letter labels, and it takes the last letter of the alphabet.
Example 3
- Input
- columnNumber = 702
- Output
- "ZZ"
Every one-letter and two-letter label is spoken for by this point: 26 of the first kind and 676 of the second come to 702, and this tray takes the last of them.
Example 4
- Input
- columnNumber = 705
- Output
- "AAC"
This tray sits three past the end of the two-letter labels, so it carries a three-letter label.
Constraints
- 1 <= columnNumber <= 2^31 - 1
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 convert_to_title(columnNumber: int) -> str:public String convertToTitle(int columnNumber)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 4 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