FastPrepPolynomial Coefficients
Problems/Polynomial Coefficients

Polynomial Coefficients

Shopify logoShopify● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Shopify online assessment for a software engineering internship, taken between July and September 2026. It was the second of three coding tasks, followed by a multiple-choice aptitude quiz, and it was set in Ruby; here you can solve it in any language.

The report gives the input form, the sign rule for the first term, the hidden 1 before x and x^2, the length limit, the coefficient limit and one example with its answer. We read the coefficient limit as a limit on each single term, and we added three rules the report does not state: a number can be 0, numbers have no extra leading zeros, and the square is always written as x^2.

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

You are given a string polynom with no spaces. It is a quadratic expression in x, written as a sum of terms. Each term has one of three forms:

  • a plain number, for example 4 (a constant term);
  • a number followed by x, for example 5x;
  • a number followed by x^2, for example 7x^2, which means 7 times x squared.

A form can be used by several terms, and the terms can be written in any order. Combine the terms of each form and return three integers in an array: the coefficient of x^2, then the coefficient of x, then the constant.

How the input is written:

  • There is a + or - sign between every two terms. The first term can start with +, with -, or with no sign, and no sign means +.
  • The number in front of x or x^2 can be left out, and then it is 1. So x^2 is the same as 1x^2, and -x is the same as -1x.
  • Numbers are written in base 10 with no extra leading zeros. A number can be 0, as in 0x.
  • The square is always written as x^2. No other powers or symbols appear.

If a form has no terms, or its terms add up to zero, its place in the answer is 0. For example, an expression whose terms all cancel gives [0, 0, 0].

Function

compute(polynom: String) → int[]

Examples

Example 1

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

The x^2 terms are 7x^2 and x^2, so they give 7 + 1 = 8 for the first place in the answer. The x terms are 5x and -24x, giving 5 - 24 = -19. The only number on its own is 4. The three places give [8, -19, 4].

Example 2

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

The first term starts with a minus sign, so -x^2 counts as -1 times x^2. In the same way, -x counts as -1 times x. The number on its own is 3, so the answer is [-1, -1, 3].

Example 3

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

A plus sign is also allowed before the first term. 12x^2 and -12x^2 cancel, and -0x adds nothing. There is no number on its own, so every coefficient is 0 and the answer is [0, 0, 0].

Example 4

polynom = "1000000x+1000000x-1000000"return = [0,2000000,-1000000]

Each number in the input is at most 1000000, but a sum can be larger: the x coefficient is 1000000 + 1000000 = 2000000. There is no x^2 term, so the answer is [0, 2000000, -1000000].

Constraints

  • 1 <= polynom.length <= 50
  • polynom contains only digits, x, ^, + and -, and follows the rules above.
  • Every number written in polynom is at most 10^6, so the coefficient of each single term is between -10^6 and 10^6.

More Shopify Online Assessment questions

  • Card Game: Best First-Player ScoreOA · Seen Nov 2026
  • Macaron Order with Set DiscountsOA · Seen Nov 2026
  • Choose Items for a BackpackOA · Seen May 2026
  • Filter Words Containing a LetterOA · Seen Aug 2025
  • Paint HouseOA · Seen Aug 2025
  • Longest Increasing SubsequenceOA · Seen May 2025
  • Find the Compromised ServerOA · Seen Apr 2025
  • Fix the First Robot InstructionOA · Seen Dec 2024
  • Validate a Directed GraphOA · Seen Mar 2018
  • Min StackOA

Similar questions at other companies

  • Simplify a Quadratic ExpressionOpenAI · OAOpenAI interview questions
  • 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

Shopify interview experiences

  • Shopify AI Pair Programming Interview: 2 Experiences
  • Shopify Intern Older Life Story: 19 Experiences (Part 4 of 4)
  • Shopify Intern Life Story and OA: 20 Experiences (Part 3 of 4)
  • Shopify Intern OOP Pairing: 20 Experiences (Part 2 of 4)
  • Shopify SWE Intern Interviews: 79 Experiences (Part 1 of 4)
All Shopify interview questionsSee Shopify hiring insights
Saved
class Solution {
    public int[] compute(String polynom) {
        // Write your code here.
    }
}
Checking account…