Leaderboard
Showing:
Value of polynomial
Easy Accuracy: 0.0% Submissions: 10 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.

Your Task:
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 

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Value of polynomial

Output Window