Given a positive integer, convert it to the corresponding Excel column title. In Excel, columns are labeled A through Z for columns 1-26, then AA, AB, through AZ for 27-52, then BA, BB, and so on. For example, 1 maps to "A", 26 maps to "Z", 27 maps to "AA", 28 maps to "AB", and 703 maps to "AAA". Return null for null input, and an empty string for values less than 1.

Examples:

Input: columnNumber = 1 Output: 'A' Explanation: Column 1 maps to the first letter A Input: columnNumber = 26 Output: 'Z' Explanation: Column 26 maps to the last single letter Z Input: columnNumber = 28 Output: 'AB' Explanation: Column 28 maps to AB (27=AA, 28=AB) Input: columnNumber = 703 Output: 'AAA' Explanation: Column 703 maps to AAA Input: columnNumber = null Output: null Explanation: Null input returns null
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay Mar/April 2026

Contest runs March 3 - April 30. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.