Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Polynomial Equivalence Function

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Polynomial Equivalence Function. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Blend's decision logic can represent algebraic calculations as sparse polynomials. Given two polynomials, determine whether they represent the same mathematical function after combining terms with equal exponents.

Each polynomial is provided as a list of terms, where every term is [coefficient, exponent] and represents coefficient * x^exponent. Terms may appear in any order, multiple terms may have the same exponent, and zero-coefficient terms may be included.

Return True if the polynomials are equivalent for every value of x; otherwise, return False.

Formal Specification

Implement are_equivalent(poly1, poly2).

  • Input: two lists of integer pairs, poly1 and poly2.
  • Output: a boolean.
  • Equivalence must be determined symbolically, not by evaluating a limited set of x values.

Constraints

  • 0 <= len(poly1), len(poly2) <= 10^5
  • Each term contains exactly two integers: [coefficient, exponent]
  • 0 <= exponent <= 10^9
  • -10^9 <= coefficient <= 10^9
  • The total number of terms across both polynomials is at most 2 * 10^5

Function Signature

def are_equivalent(poly1, poly2):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output