DSA interview question
A stack-machine assembler writes expressions in postfix (for example ABC/-AK/L-*), but a symbolic-math library it feeds requires prefix (*-A/BC-/AKL). Postfix is read naturally left to right: operands are pushed, and when an operator arrives its two operands are already on the stack, right on top, left below. Pop them in that order and push op + left + right.
Example: ABC/-AK/L-* → *-A/BC-/AKL.
string postfixToPrefix(const string& post); // single-character operands; binary operators
| Input | Output | Explanation |
|---|---|---|
ABC/-AK/L-* | *-A/BC-/AKL | |
ab+ | +ab | |
ab+cd-* | *+ab-cd | |
ab+c- | -+abc | |
a | a |
(Confirm: the postfix expression is valid; operands are single characters; all operators are binary.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in