Bloomberg | Onsite | Minimum number of steps to reach a number from 1 with 2 operations

Recently, in an interview I reached till the onsite rounds. Did really well till the last round. In the very last round, I solved two BFS based questions and the interviewer moved to a 3rd question. I think this question cost me the offer.

Question: It's possible to construct any integer n using a series of two operations: multiply by 2 or divide by 3. Find the minimum number of steps required to construct an integer starting from 1.

Eg: 5 => 2*2*2*2/3
    10 => 2*2*2*2/3*2

I find questions like this very difficult to solve. I understand I can write a recursive solution and maybe maintain a map like we do for dp. But, this question tripped me because there was a division operation. Does anybody know how to develop an intuition for problems like this? Any mathematics or puzzle books suggestions? The interviewer said the solution for this is BFS. I don't know how that would work. Does anybody know an intuitive solution?

Comments (9)