Skip to content
Katabench
Try free

Excel Column Number

Easy About 8 min Free, no account needed

Spreadsheet columns are base-26 with no zero digit.

The brief

Spreadsheet columns are lettered A, B, ..., Z, AA, AB, .... Given a column title, return its 1-based number (A=1, Z=26, AA=27).

The hidden trap

Columns look like base-26, but there is no zero digit: A is 1, Z is 26, and AA follows Z rather than BA, so a lookup table built for ordinary base-26 is off by one at every position. The hidden tests reach FXSHRXW (int.MaxValue), where reconstructions that pass through floating point (Math.Pow) start to wobble by one. Stay in exact integer arithmetic.

Starter code

C#
using System;

public class Solution
{
    // TODO: return the 1-based column number for an Excel column title.
    public long TitleToNumber(string column)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

What it practices

Math and number theory
Replace enumeration with a formula: GCD, modular arithmetic, digit math and closed-form counting.
String processing
Parse, scan and match text character by character with correct edge cases.

Related katas