powers of 2 interview test. (with additional generic solution)