Given a string of numbers and a number of multiplication operators, what is the highest number one can calculate?

后端 未结 9 1779
醉话见心
醉话见心 2021-01-30 11:22

This was an interview question I had and I was embarrassingly pretty stumped by it. Wanted to know if anyone could think up an answer to it and provide the big O notation for it

9条回答
  •  不知归路
    2021-01-30 12:13

    I'm pretty sure that the answer is to simply put the *s right before the biggest digits, so that the largest digit have the biggest impact. For example, if we have

     1826456903521651 
    

    and we have five multiplications, this would be the answer.

     1*82*645*6*903521*651 
    

    So the running time would be linear.

    Edit: Okay, so this is wrong. We have two counterexamples.

提交回复
热议问题