Skip to the code
cf.
+25 XP

#654 Data Grid Column Label

medium

A spreadsheet-style data grid labels its columns A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ZZ, AAA, and so on. Column 1 is A.

Write columnLabel(n) that returns the label of column n.

Example 1

Input: n = 1
Output: "A"

The first column is A.

Example 2

Input: n = 28
Output: "AB"

After Z (26) comes AA (27), then AB (28).

Constraints

  • 1 <= n <= 2^31 - 1
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).