85 minutes C/C++ only.
I gave them a brute force algorithm then I got rejected two days later :/
Anyway the description is as bellow:
Minimum length of (-2) base integers.
Given an integer, it can be represented using (-2) base.
Example:
original | (-2) base
-2 | 10
4 | 100
-8 | 1000
Write a function that returns the (-2) base integer and the length of it must be the smallest of all possible representations.
vector<int> convert(int integer)I can't remember the test case but one thing is that it's definitely not an easy or medium level question because it has so many pitfalls.
Hope it helps.
Related problems: