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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Bijective Numeration
Base Conversion
String Parsing
Off-by-One Errors
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • label_to_index("A") = 1, "Z" = 26, "AA" = 27, "ZZ" = 702, "AAA" = 703.
  • index_to_label is the exact inverse for every n >= 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...


Submit Your Answer
Markdown supported