Ctrl K

Spreadsheet Column Label

Easy
Spreadsheet columns are labeled with letters: A, B, …, Z, then AA, AB, …, AZ, BA, …, ZZ, then AAA, and so on. Given a column number index, counting from 1, return its label: 1 is A, 26 is Z, 27 is AA.
Example 1
index=3 → 'C'

The third column is C.

Example 2
index=52 → 'AZ'

Columns 27 to 52 are AA through AZ, and the last one is AZ.

Example 3
index=703 → 'AAA'

The labels of length 1 and 2 cover 702 columns (up to ZZ), so the next one is AAA.

Constraints
  • 1 ≤ index ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Index EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings Easy
loading Python…
Input
index=3
Expected
'C'

Run checks the first 3 tests in your browser. Submit checks all 41 tests on the server, hidden ones included.