Hi, everyone.
So today we are going to solve this question Excel sheet column no.
OK, so what is the question?
So question is very simple.
Basically, we will be provided with the column title as it's appeared in the Excel sheet and we have
to find the corresponding column number.
OK, so basically the input will be a string.
And this string is basically the column title and it will contain all uppercase alphabets.
OK, it will contain all uppercase alphabet.
And what we have to do, so basically we have to find its corresponding number.
Let us take some example to understand, OK, for example, this is the column title, then the column
number is one.
OK, if the column title is B, then no column number is two.
If the column title is Z, then the column number is 26.
OK, so let's see this this one example.
So this is basically one and this is basically going to multiply one.
And if you will add these two, I will get twenty seven.
OK, so B is basically two.
This is basically during the six multiply the value of A's one.
And if you will add these two I will get 28.
OK, so this is the value of a is one.
So the value of this is basically 26 multiply when the value of this is basically 26, multiply 26,
multiply one.
And if you will add these three, then you will get seven zero three.
OK, so the value of Y is basically twenty five.
The value of that is basically 26 multiply and the value of that is 96.
If you will add these two you will get seven zero one.
OK, so this isn't a thing, this is just the implementation problem.
OK, it is only implementation problem.
So what we have to do.
So what we will do.
Suppose I have a string, let's say ABC.
So this is basically the column title what I will do.
So take the value of the which is one, two, three, four.
So its value will be for the value of these.
Basically three and three will multiply it by 26.
The value of B is basically two and we will multiply it with 36 and 226.
Similarly, the value of is basically one and we will multiply it with 26, multiply 26, multiplied
26, multiply one and then we will add all these folds.
OK, so we will add.
So basically what we have to do, so suppose this is.
A very long string then, but we have to do so, I will start reading from the end, OK, I started
reading from the end.
I will take a variable power, which is initially one, and each time this power will get multiplied
by 26.
OK, and I will find out the value of the character and I will multiply the value of character with
the power.
OK, so let's read the cold.
So basically, this question is present only.
OK, so now let's take the call.
So what they're going to do is so the plan is very simple.
Let us take one example to understand.
So suppose I have this a A and a OK, so I will start trading from the end.
Let's take a variable answer, which is initially zero.
OK, so the value of A is one and initially the value of power is one.
OK, so the value of phase one.
So what I will do, I will write sequels, current answer plus the value of the character.
So in this case, this is one.
OK, so one multiply power.
So power is also seven, so cyclers zero plus one into one sort of answer becomes one.
OK, now let us come here.
So the value of A is basically one, but it will get multiplied by 26.
OK, so what I will do, I will right here.
Power equals power.
Multiply 26 and I'll execute this line again.
OK, so this is basically on set equals the current value of Unseld, which is one, so the value of
A is one and the value of power is basically 26.
OK, if you will add these two, you will get 27 now for this one.
So the answer is basically 27 plus.
So what will happen at this point?
I will multiply power by 26.
So the value of power was already 26.
So this is the 626, basically 26 square.
So this will be six, seven, six.
OK, so six, seven, six multiplied the value of eight, which is one.
And if you will add these two, so this will basically so seven, six, seven to nine and 10, so this
will be basically seven zero three.
OK, so let's see about.
So seven zero three is the right answer.
OK, so now let us right the good.
So as discussed initially, my.
I said, this is zero.
And initially.
I have a power variable, which is initially one, OK, I will start outrating from the end, so let's
find out the size of the string.
So as Nazis'.
Now, after finding the sites, we have to read from the end.
OK, so now let's hydrate.
So the last FedExes and minus one and the first index is basically zero eight minus minus.
So what we have to write, so say, was.
And surplus, first of all, we have to find the value.
So this is SFI, as if I will give me the corrected minus 64 y 64 because the ASCII value of capital.
OK, so I am writing here.
SFI minus 64.
So this is basically will give me a character.
OK, and this is 64, basically the assembly of capital is 65, OK, but here in our problem, the value
of it is basically one.
So what I will do, I will do 65 minus 64.
So the value of it will become one.
OK, so basically this is character minus integer.
So whenever the situation is minus integer, what will happen?
So this character will be converted to Tasca value, for example, if this character is be.
So that's how I value what will become so it will become 66 and I am subtracting 64, so it will become
two and obviously the value of being for our problem is basically two.
OK.
And now what we have to do so we have to multiply with the power and now the power will increment,
so power equals power, multiply 26.
OK, and finally, when the loop will end, we can return our answer.
OK, so very simple.
OK, so now let's send it out answer.
OK, so what is happening here is we are getting rain error at this late hour equals power multiplied
26 and why we are getting runtime error.
So basically.
So basically, we have in digital tape, so doing digitally type the maximum number, it can stories
up to two to the power 31 OK in C++.
So this is nearly ten to the power line.
OK, now suppose this power number is a very big number and what we are doing, so we are multiplying
this big number by 26, then what can happen?
So this resulting number, it can become greater than 10 to the power nine, which is the range of the
integer.
So if this is the scenario, what will happen?
So we will get runtime error because this big number cannot be stored in an integer variable and this
power is basically in digital type.
OK, so to solve this question, what we can do, so we have a data type Longlong, so the range of
long under type is basically it can store numbers which are approved into the power rating.
OK, so this is the range for long, long to the type.
So if we will use long, long red tape for the power variable.
We will not get intimidated, OK, because this big number can be stored in the long, long delay type,
OK, so let's change the type of the power variable.
So instead of using integer, what we will use, we will use long, long and hopefully they should work.
OK, now let's admit.
OK, so our goal is working fine.
OK?
So now let us discuss the time and the space complexity for our record.
OK, so basically the space complexities are the rough when we are just creating only a few variables,
OK?
And the time complexity is basically all that often the Gulf and where and is basically the size of
this string.
OK, so we are just iterating from the end of the string.
Towards the first.
OK, so we are retreating from the end of the string.
OK, so the time complexity is basically linear and the space complexity is basically big off one.
OK, so if you have any doubt in this question, you can ask me.
OK, thank you.