Differentiate a Polynomial
Updated
Problem statement
Return the formal derivative of the polynomial described by coefficients.
For this exercise, assume the coefficient at index i multiplies x^i. Coefficients are integers and powers are nonnegative integers. For example, [5, 3, 2] represents 5 + 3x + 2x^2.
Return coefficients in the same ascending-power order. Remove trailing zero coefficients from the result, but return [0] for the zero polynomial. The input may contain trailing zeros. The derivative of a constant is zero.
Function
differentiatePolynomial(coefficients: int[]) → int[]Examples
Example 1
coefficients = [5, 3, 2]return = [3, 4]The derivative of 5 + 3x + 2x^2 is 3 + 4x, so the result is [3, 4].
Example 2
coefficients = [4]return = [0]A constant has derivative zero. Its canonical coefficient array is [0].
Example 3
coefficients = [1, 0, 0, -2]return = [0, 0, -6]The constant disappears and -2x^3 becomes -6x^2. The zero coefficients keep the missing constant and x terms in their correct positions.
Constraints
- 1 <= coefficients.length <= 2000
- -100000 <= coefficients[i] <= 100000
- Every input coefficient is an integer.
More Squarepoint Capital interview questions
- Mutable Record Store with Error ResultsONSITE INTERVIEW · Seen Sep 2026
- Maximum SubarrayONSITE INTERVIEW · Seen Aug 2026
- Product of Array Except SelfONSITE INTERVIEW · Seen Aug 2026
- Estimate Pi with a Finite SeriesONSITE INTERVIEW · Seen Oct 2025
- In-Memory Directory and File OperationsONSITE INTERVIEW · Seen Oct 2025
- Count C++ Constructor and Assignment CallsONSITE INTERVIEW · Seen Jun 2025
- Observe a Lazy GeneratorONSITE INTERVIEW · Seen Feb 2025
- Order Matching on ExecuteONSITE INTERVIEW · Seen Dec 2024
- Accumulate Numeric Value ObjectsONSITE INTERVIEW · Seen Sep 2024
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Plus OneDruva · ONSITE INTERVIEW
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
- Exact-Sixty Dice Game ValueJane Street · ONSITE INTERVIEWJane Street interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Alternating Index Square SumAccenture · ONSITE INTERVIEWAccenture interview questions
- Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
- Add One to a Number Represented as DigitsOracle · ONSITE INTERVIEWOracle interview questions
- Streaming Entropy, Part 1: Batch EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions