Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3510
@sushant_a 3459
Value of polynomial
Easy Accuracy: 16.33% Submissions: 68 Points: 2

Given a polynomial represented as poly[] of size n and a value x, compute value of the polynomial for given x.  The result should be computed under modulo 109+7.

Example 1:

Input: n = 4, x = 3
poly = {2, -6, 2, -1}
Output: 5
Explaination: Output is value of 2x3 - 6x2 +
2x - 1 for x = 3.

Example 2:

Input: n = 4, x = 2
poly = {1, 2, 0, 4}
Output: 20
Explaination: Output is value of x3 + 2x2 + 4
for x = 2.

You do not need to read input or print anything. Your task is to complete the function value() which takes n, poly and x as input parameters and returns the value of the polynomial modulo 109 + 7.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ n ≤ 2000
-1000 ≤ poly[i] ≤ 1000
1 ≤ x ≤ 1000

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:

Value of polynomial