I keep getting these hard interview questions. This one really baffles me.
You're given a function poly
that takes and returns an int
. It's actually a polynomial with nonnegative integer coefficients, but you don't know what the coefficients are.
You have to write a function that determines the coefficients using as few calls to poly
as possible.
My idea is to use recursion knowing that I can get the last coefficient by poly(0)
. So I want to replace poly
with (poly - poly(0))/x
, but I don't know how to do this in code, since I can only call poly
. ANyone have an idea how to do this?
a + b.x + c.x^2 + d.x^3 + ...
, evaluating forx=0
will give youa
. – Chelseychelsie