Table: Terms
+-------------+------+ | Column Name | Type | +-------------+------+ | power | int | | factor | int | +-------------+------+ power is the column with unique values for this table. Each row of this table contains information about one term of the equation. power is an integer in the range [0, 100]. factor is an integer in the range [-100, 100] and cannot be zero.
You have a very powerful program that can solve any equation of one variable in the world. The equation passed to the program must be formatted as follows:
"<sign><fact>X^<pow>" where:
<sign> is either "+" or "-".<fact> is the absolute value of the factor.<pow> is the value of the power.1, do not add "^<pow>".
power = 1 and factor = 3, the term will be "+3X".0, add neither "X" nor "^<pow>".
power = 0 and factor = -3, the term will be "-3".Write a solution to build the equation.
The result format is in the following example.
Example 1:
Input: Terms table: +-------+--------+ | power | factor | +-------+--------+ | 2 | 1 | | 1 | -4 | | 0 | 2 | +-------+--------+ Output: +--------------+ | equation | +--------------+ | +1X^2-4X+2=0 | +--------------+
Example 2:
Input: Terms table: +-------+--------+ | power | factor | +-------+--------+ | 4 | -4 | | 2 | 1 | | 1 | -1 | +-------+--------+ Output: +-----------------+ | equation | +-----------------+ | -4X^4+1X^2-1X=0 | +-----------------+
Follow up: What will be changed in your solution if the power is not a primary key but each power should be unique in the answer?
Loading editor...
{"headers":{"Terms":["power","factor"]},"rows":{"Terms":[[2,1],[1,-4],[0,2]]}}