FastPrepSimplify a Quadratic Expression
Problems/Simplify a Quadratic Expression

Simplify a Quadratic Expression

OpenAI logoOpenAI● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OpenAI online assessment for a full-time role. The report gives the normalization of quadratic, linear, and constant terms, and an input with no spaces. We added the full grammar and the number limits.

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

Given a valid string polynom representing a quadratic expression, combine like terms and return the final coefficients.

The expression is a sum of terms in any order. Each term is one of:

  • a constant such as 4 or -12;
  • a linear term such as 5x, -x, or +x;
  • a quadratic term such as 7x^2, -x^2, or +x^2.

A missing coefficient before x means 1. Return an array [a, b, c], where the simplified expression is ax^2 + bx + c.

Function

simplifyQuadratic(polynom: String) → int[]

Examples

Example 1

polynom = "5x+7x^2+4+x^2-24x"return = [8,-19,4]

The quadratic coefficient is 7 + 1 = 8, the linear coefficient is 5 - 24 = -19, and the constant is 4.

Example 2

polynom = "x^2-x+1"return = [1,-1,1]

The omitted coefficients of x^2 and -x are 1 and -1.

Example 3

polynom = "-3+2x^2+3-2x^2"return = [0,0,0]

Both the quadratic terms and the constant terms cancel.

Constraints

  • 1 <= polynom.length <= 100000.
  • polynom contains no spaces and is a valid sequence of signed constant, x, and x^2 terms.
  • Every explicit coefficient is a base-10 integer.
  • The final three coefficients fit in a signed 32-bit integer.

More OpenAI Online Assessment questions

  • Count Routes Through Four Shop TypesOA · Seen Oct 2026
  • Digit-Sum Sequence Join PointOA · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
  • Password Clues and the Next CommandOA · Seen Oct 2026
  • Longest Increasing Price SubsequenceOA · Seen Oct 2026
  • Macaron Order PriceOA · Seen Oct 2026
  • Shortest Atom Action PathOA · Seen Oct 2026
  • Minimum-Cost Color SequenceOA · PHONE SCREEN · Seen Oct 2026
  • Largest Microorganism After ConsumptionOA · Seen Oct 2026
  • Invert or Blur an ImageOA · Seen Sep 2026

Similar questions at other companies

  • Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
  • Is This Date a Weekend?Salesforce · OASalesforce interview questions
  • Smallest Value for a Linear Expression ModuloIntel · OA
  • Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Evaluate a Flat Expression or Report Invalid InputMeta · PHONE SCREENMeta interview questions
  • Strict Text to Integer for a Given SizeAdobe · PHONE SCREENAdobe interview questions
  • Evaluate an Arithmetic ExpressionAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Solve a Linear Equation in xNutanix · PHONE SCREENNutanix interview questions
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions

Interview reports that mention this question

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int[] simplifyQuadratic(String polynom) {
        // Write your code here.
    }
}
Checking account…