Magicsheet logo

Excel Sheet Column Number

Easy
77%
Updated 6/1/2025

Excel Sheet Column Number

What is this problem about?

The Excel Sheet Column Number interview question is a base-conversion problem. You are given a string representing a column title as it appears in an Excel sheet (e.g., "A", "B", "Z", "AA", "AB"), and you need to return its corresponding integer column number. In this system, "A" is 1, "B" is 2, ..., "Z" is 26, "AA" is 27, and so on.

Why is this asked in interviews?

Tech companies like Goldman Sachs and Microsoft ask this Math and String coding problem to test your understanding of positional numeral systems. It's essentially a variation of converting a number from base-26 to base-10. It evaluates your ability to iterate through a string and apply a mathematical formula while handling potential integer overflows.

Algorithmic pattern used

The problem follows a Base-26 Conversion pattern.

  1. Initialize result = 0.
  2. Iterate through the string from left to right.
  3. For each character c:
    • Convert c to its numeric value (A=1, B=2, ..., Z=26).
    • Update result: result = result * 26 + value.
  4. Return result.

Example explanation

String: "AB"

  1. Process 'A': Value = 1. result = 0 * 26 + 1 = 1.
  2. Process 'B': Value = 2. result = 1 * 26 + 2 = 28. Wait, "AA" is 27, so "AB" should be 28. Correct.

String: "ZY"

  1. Process 'Z': Value = 26. result = 0 * 26 + 26 = 26.
  2. Process 'Y': Value = 25. result = 26 * 26 + 25 = 676 + 25 = 701.

Common mistakes candidates make

  • Zero-indexing confusion: Thinking 'A' is 0. In Excel, the system is 1-indexed (there is no "0" digit), which is slightly different from standard base conversions.
  • Power Calculation: Calculating 26^n inside the loop using a power function, which is less efficient than the result * 26 + next approach.
  • Wrong loop direction: Trying to process from right-to-left without correctly managing the powers of 26.

Interview preparation tip

Always relate these problems to the decimal system (base-10). Converting "123" to a number is just ((1 * 10) + 2) * 10 + 3. Base-26 works exactly the same way, just replace 10 with 26.

Similar Questions