Compare Polynomial Growth

Write a program to compare the asymptotic growth of two nonzero polynomials with non-negative integer coefficients, f(n) and g(n).

You are given two polynomials represented as 2D arrays (vectors). Each inner array contains two numbers representing a term in the polynomial: [coefficient, exponent]. Repeated exponents are allowed in the input, and terms with a zero-coefficient contribute nothing to the polynomial's degree. At least one coefficient in each polynomial is guaranteed to be positive.

Determine the leading nonzero degrees of both polynomials to compare their growth as n tends to infinity. Do not attempt to evaluate the polynomials at a large sample n, as the exponents and coefficients can be extremely large. The submission is an executable code with exact output, not an asymptotic proof.

Output Format: Output exactly three space-separated strings: YES or NO, indicating whether f(n) is O(g(n)), Ω(g(n)), and θ(g(n)), in that order.

Note: Print exactly one space between the words and a newline at the very end. Do NOT print any trailing spaces at the end of the line.

Example 1:

Input:

f = [[3, 2], [5, 1], [2, 0]]
g = [[7, 2]]

Output:

YES YES YES

Explanation:

f(n) = 3n2 + 5n + 2 and g(n) = 7n2. The highest degree of f(n) is 2, and the highest degree of g(n) is 2. Since their maximum degrees are equal, f(n) is O(g(n)), Ω(g(n)), and θ(g(n)).

Example 2:

Input:

f = [[1, 1]]
g = [[1, 2]]

Output:

YES NO NO

Explanation:

f(n) = n and g(n) = n2. The maximum degree of f(n) is 1, which is strictly less than the maximum degree of g(n) (which is 2). Therefore, f(n) is O(g(n)), but it is not Ω(g(n)) or θ(g(n)).

Now Your Turn!

Pick the correct output for the given input

Input:

f = [[5, 3], [0, 5], [2, 1]]
g = [[10, 2], [100, 0]]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

1 <= number of terms in f and g <= 100000

0 <= coefficient <= 109

0 <= exponent <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
void comparePolynomials(vector<vector<int>>& f, vector<vector<int>>& g) {
// Write your code here
}
};
Test Case

Input:

F
G