All problems
0414EasyMathString

Seed Tray Label

Tracked in this browser only
Write code

Trains the technique from

LeetCode 168Excel Sheet Column Title

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def convert_to_title(columnNumber: int) -> str:
Java
public String convertToTitle(int columnNumber)
September 7
Apply