FastPrepConvert Infix to Postfix
Problems/Convert Infix to Postfix

Convert Infix to Postfix

Adobe logoAdobe● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem rewrites an infix expression in postfix form. A post from February 2022, by a student later selected for Adobe's 2022 Product Intern role, describes one live video interview. It followed an online test and a resume screen. Of the two coding tasks in that interview, a linked-list reversal came second and this conversion first. The author coded both in a self-picked editor over a shared screen. The post names the task in one line and gives no operator set, precedence, operand form or examples.

Our choices: operands are single lower-case letters. The operators are +, -, *, / and ^, with ^ above * and /, which are above + and -. ^ groups from the right and the others from the left. Parentheses may appear and are dropped from the answer. There are no spaces and no unary minus. The input has 1 to 1999 characters, with parentheses at most 100 deep. The examples are new.

Our version is about 80% the same as the reported question.

You are given an expression s in the usual infix form, where each operator sits between its two operands. Return the same expression in postfix form, where each operator comes right after its two operands.

Every operand is a single lower-case letter. The operators, from loosest to tightest, are: + and -; then * and /; then ^. Operators of the same level are grouped from left to right, except ^, which is grouped from right to left (so a^b^c means a^(b^c)). Parentheses make the part inside them one operand; they do not appear in the answer.

The answer has no spaces. For example, p*(q-r) becomes pqr-*.

Function

toPostfix(s: String) → String

Examples

Example 1

s = "x-y/z+w"return = "xyz/-w+"

Division binds tighter, so y/z becomes yz/ first. Then - and + have the same level and are done left to right: x-(y/z) gives xyz/-, and adding w gives xyz/-w+.

Example 2

s = "(m+n)*k^j^i"return = "mn+kji^^*"

The parentheses make m+n one operand: mn+. ^ groups from the right, so k^j^i means k^(j^i), which is kji^^. Multiplying the two parts gives mn+kji^^*.

Example 3

s = "t-(u-v)-s"return = "tuv--s-"

The inner u-v is uv-. The two outer minus signs are done left to right: t minus that gives tuv--, and minus s gives tuv--s-.

Constraints

  • 1 <= s.length <= 1999
  • s consists of lower-case English letters and the characters '+', '-', '*', '/', '^', '(' and ')'.
  • s is a valid expression: letters and operators alternate, starting and ending with a letter, where a valid expression inside a pair of parentheses also counts as a letter.
  • Parentheses are nested at most 100 deep.

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREENRoblox interview questions
  • Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Rich Text Parser Part 3 (Depth Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Decode an Encoded StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Parse Indented YAML MappingsUber · PHONE SCREENUber interview questions
  • Decode Repeated GroupsWaymo · PHONE SCREENWaymo interview questions
  • Convert Email Text to Structured MarkupZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
  • Parse Variable, Expression, and Application TreesSambaNova Systems · PHONE SCREEN · ONSITE INTERVIEWSambaNova Systems interview questions

Interview reports that mention this question

  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public String toPostfix(String s) {
        // Write your code here.
    }
}
Checking account…