Render the Polynomial Filter
Problem
A signal-processing tool stores a polynomial as a set of pieces in `polynomial_pieces` with columns `(degree, coefficient)`. `degree` is the primary key and is a non-negative integer; `coefficient` is an integer that may be positive or negative. Render the whole polynomial as one string `formula` of the form `<sign><coeff><var-part><sign><coeff><var-part>...=0`.
Rules:
- Pieces appear in descending order of `degree`.
- The variable is `n`. For `degree` 0 the piece has no variable part: `<sign><coeff>`. For `degree` 1 it is `<sign><coeff>n`. For any higher degree it is `<sign><coeff>n^<degree>`.
- Every coefficient is prefixed by its sign: `+` when positive, `-` when negative (the minus comes from the number itself).
- The whole string ends with `=0`.
Tables
Example rows — the live problem includes the full dataset.
| degree | coefficient |
|---|---|
| 3 | 2 |
| 1 | -5 |
| 0 | 7 |
Expected output
Your answer should return 1 row with the columns formula.
Starter code (SQL)
SELECT *
FROM polynomial_pieces;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock