Convert Google Sheets Column Labels to Numbers and Back
Last updated: November 29, 2026
Quick Overview
Implement two functions for a spreadsheet: one that converts a column label such as "A", "Z", "AA", or "ZZ" into its 1-based column number, and one that converts a column number back into its label.
0
0
0 solved
Implement two functions for a spreadsheet: one that converts a column label such as "A", "Z", "AA", or "ZZ" into its 1-based column number, and one that converts a column number back into its label.
A Sheets-flavored Google phone screen that looks trivial until the reverse direction. The interviewer is checking whether you recognize bijective base-26 (no zero digit) and handle the off-by-one at Z, AZ, and ZZ correctly.
What the Interviewer Expects
- Identifies the system as base 26 with digits 1 to 26 and no zero
- Implements label to number with Horner's rule
- Fixes the reverse direction with a subtract-one step before each modulo
- Tests boundaries such as 26, 27, 52, 702, and 703
- Validates bad characters
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Parse a full cell reference like "BC12" into (row, column).
- Parse a range like "A1:C10" and count the cells it covers.
- How would you generalize to any alphabet size?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
label_to_index("A") = 1,"Z" = 26,"AA" = 27,"ZZ" = 702,"AAA" = 703.index_to_labelis the exact inverse for everyn >= 1.- Lowercase input is accepted; anything that is not a let...
High-Level Design
Labels are numbers in bijective base 26: each letter is a digit from 1 to 26, and there is no zero. Reading left to right is ordinary positional evaluation, n = n * 26 + digit. Going back is where p...