DSA interview question
A compiler pipeline receives expressions in prefix form from one tool and must hand them to a stack-based evaluator that expects postfix. Both notations are parenthesis-free and unambiguous, so no precedence rules are involved. Only the operator placement moves. Scan the prefix string right to left: push operands; for an operator, pop the left operand (top) and the right operand, and push left + right + op.
Example: *-A/BC-/AKL → ABC/-AK/L-*.
string prefixToPostfix(const string& pre); // single-character operands; binary operators
| Input | Output | Explanation |
|---|---|---|
*-A/BC-/AKL | ABC/-AK/L-* | |
+ab | ab+ | |
*+ab-cd | ab+cd-* | |
-+abc | ab+c- | |
a | a |
(Confirm: the prefix 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