Degree of Polynomial solution codechef
In mathematics, the degree of polynomials in one variable is the highest power of the variable in the algebraic expression with non-zero coefficient.
Chef has a polynomial in one variable xx with NN terms. The polynomial looks like A0⋅x0+A1⋅x1+…+AN−2⋅xN−2+AN−1⋅xN−1A0⋅x0+A1⋅x1+…+AN−2⋅xN−2+AN−1⋅xN−1 where Ai−1Ai−1 denotes the coefficient of the ithith term xi−1xi−1 for all (1≤i≤N)(1≤i≤N).
Find the degree of the polynomial.
Note: It is guaranteed that there exists at least one term with non-zero coefficient.
Degree of Polynomial solution codechef
Input Format
- First line will contain TT, number of test cases. Then the test cases follow.
- First line of each test case contains of a single integer NN – the number of terms in the polynomial.
- Second line of each test case contains of NN space-separated integers – the ithith integer Ai−1Ai−1 corresponds to the coefficient of xi−1xi−1.
Output Format
For each test case, output in a single line, the degree of the polynomial.
Degree of Polynomial solution codechef
- 1≤T≤1001≤T≤100
- 1≤N≤10001≤N≤1000
- −1000≤Ai≤1000−1000≤Ai≤1000
- Ai≠0Ai≠0 for at least one (0≤i<N)(0≤i<N).Through this contest, selected students get access to a free 6 month LinkedIn Premium subscription which helps students:
- Discover & apply to 20M+ jobs/internships on LinkedIn
- Reach out to hiring managers/recruiters/mentors directly
- Find career paths that people similar to them have taken
- Learn from over 17K expert-led LinkedIn Learning courses (technical & soft-skills) with certificates
Sample Input 1
4
1
5
2
-3 3
3
0 0 5
4
1 2 4 0
Sample Output 1
0
1
2
2
Degree of Polynomial solution codechef
Test case 11: There is only one term x0x0 with coefficient 55. Thus, we are given a constant polynomial and the degree is 00.
Test case 22: The polynomial is −3⋅x0+3⋅x1=−3+3⋅x−3⋅x0+3⋅x1=−3+3⋅x. Thus, the highest power of xx with non-zero coefficient is 11.
Test case 33: The polynomial is 0⋅x0+0⋅x1+5⋅x2=0+0+5⋅x20⋅x0+0⋅x1+5⋅x2=0+0+5⋅x2. Thus, the highest power of xx with non-zero coefficient is 22.
Test case 44: The polynomial is 1⋅x0+2⋅x1+4⋅x2+0⋅x3=1+2⋅x+4⋅x21⋅x0+2⋅x1+4⋅x2+0⋅x3=1+2⋅x+4⋅x2. Thus, the highest power of xx with non-zero coefficient is 22.