Instructure interview question

Q1: Implement Reverse Polish Notation

Interview Answer

Anonymous

20 July 2021

class Solution { public: int evalRPN(vector& tokens) { if (tokens.size() ops = { "+", "-", "*", "/" }; stack st; int ans = 0, numA, numB; for (auto token: tokens) { if (ops.find(token) != ops.end()) { numB = st.top(); st.pop(); numA = st.top(); st.pop(); if (token == "+") ans = numA + numB; else if (token == "-") ans = numA - numB; else if (token == "*") ans = numA * numB; else ans = numA / numB; st.push(ans); } else { st.push(stoi(token)); } } return ans; } };

Instructure Interview Question: Q1: Implement Reverse Polish Notation | Glassdoor