DSA interview question
A debugger for a stack-based virtual machine shows the bytecode's expressions in postfix, like ab*c+, but developers want to read them as ordinary fully parenthesised infix, like ((a*b)+c). Postfix is already in evaluation order, so the conversion mirrors evaluation. Read left to right, push operands, and when an operator appears, pop the right operand (top) and the left operand, then push "(" + left + op + right + ")".
Example: ab*c+ → ((a*b)+c).
string postfixToInfix(const string& post); // single-character operands; binary operators
| Input | Output | Explanation |
|---|---|---|
ab*c+ | ((a*b)+c) | |
ABC/-AK/L-* | ((A-(B/C))*((A/K)-L)) | |
ab+ | (a+b) | |
abc++ | (a+(b+c)) | The grouping comes from the postfix order |
a | a |
(Confirm: the postfix expression is valid; every binary operation is wrapped in parentheses.)
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