X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Evaluation of Postfix Expression
Easy Accuracy: 53.28% Submissions: 33801 Points: 2

Given string S representing a postfix expression, the task is to evaluate the expression and find the final value. Operators will only include the basic arithmetic operators like *, /, + and -.

Example 1:

Input: S = "231*+9-"
Output: -4
Explanation:
After solving the given expression,
we have -4 as result.


Example 2:

Input: S = "123+*8-"
Output: -3
Explanation:
After solving the given postfix
expression, we have -3 as result.


You do not need to read input or print anything. Complete the function evaluatePostfixExpression() that takes the string S denoting the expression as input parameter and returns the evaluated value.

Expected Time Complexity: O(|S|)
Expected Auixilliary Space: O(|S|)

Constraints:
1 ≤ |S| ≤ 105

0 ≤ |Si|≤ 9 (And given operators)

We are replacing the old Disqus forum with the new Discussions section given below.