Excel Sheet Column Problem

Introduction

In this algorithm challenge on LeetCode, I decided to tackle the Excell Column Sheet Problem. This problem required me to take an alphabet string that represented integer values, for example, the letter “A” would represent 1, “B” would represent 2, and so forth. However, there is a particular trick to this problem. If the string happened to be “AA” it would result in 27. The base number, which is 26 is added to the string value. For an understanding, let’s break it down below.

The Breakdown

My initial thought process was to store the letters into objects with key-value pairs. This would allow me to connect the letter and number to the string in my arguments. Here is a better look below.

I created a variable called num and set it to zero. This would later be used to increment the number and return it.

Furthermore, I looped through the entire string. Within the loop, I decided to multiply the num to the base and add it to the object of the current index. Here is a better look below.

Once those steps were completed I simply return the num. Here is a full look below.

Thanks for reading. if there are any questions just post in the comment?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store