Hi everyone.
Let's do this question.
Evaluate the value of an arithmetic expression in reverse Polish notation c example.
So this is an example of reverse Polish notation.
All right.
So valid operators are plus minus into and division.
Note that division between two integers integers should truncate towards zero.
That means you have to round it down.
It is guaranteed that the given RPN or reverse Polish notation expression is always valid.
That means the expression would always evaluate to a result, and there will not be any division by
zero operation, so we don't need to check that.
So there can be these edge cases.
And we don't need to be worried about that because it's guaranteed that the expression will be valid.
All right.
The input is an array of strings where each element is either a valid operator or an integer.
So this is an example.
So let's take a look at this example over here to understand this question in a better manner.
Let's say the input given is this array over here.
So you can see over here we have a string with value one, a string with value two and a string with
the plus operator.
Now this means we take this one over here which is this one.
We take this two which is the second number.
And then we apply this operator over here.
And this expression if this is the input the output expected is equal to three.
Now let's take a look at one more example to understand this better.
Let's say the array given is one, two three plus and minus.
Now in this case we first have to evaluate this over here two three and plus.
So we can see that this is plus.
So the two numbers before it we have two and three.
So this actually this part over here is two.
Plus three.
So this simplifies to five.
And then it's equal to one five and minus which is one minus five.
That's how we get one minus five over here which is equal to minus four.
All right.
So we have understood the question.
Now let's take a look at a few test cases.
Let's say we already have taken care of these two test cases.
So if it's one, two and plus, it means one plus two, that's equal to three, one, two, three plus
and minus.
So two three plus this over here simplifies to five.
And then we get it should be one minus five right.
So this is one and then five.
So this is equivalent to one five and minus.
And this simplifies to one minus five which is equal to minus four.
And if the expression expression is four three and division.
So this is equal to four divided by three right.
And this is equal to 1.33 etc..
And in the question it's mentioned that in the case of division this has to be truncated towards zero.
So that means this has to be rounded down.
So 1.33 becomes one.
All right.
So again let's take a look at a bigger bigger example.
All right.
So let's say this is the array which is given to us.
Now let's try to simplify this.
We see two then three then four.
And then we have plus over here.
So the previous two over here is three and four.
So this over here simplifies to three plus four which is equal to seven.
So we have two seven and then a minus.
So this over here simplifies to two minus seven.
Right.
So two minus seven gives us minus five.
So let me just remove this.
And I'm just replacing this with minus five.
And then we have minus five seven and into.
So this is minus five into seven which is equal to -35.
So if this array was the input then we would have to return -35.
So we have got a good understanding of the question.
So let's go ahead and think about how we can solve this question in the next video.