Tricky Google interview question

前端 未结 21 1677
花落未央
花落未央 2020-12-22 15:39

A friend of mine is interviewing for a job. One of the interview questions got me thinking, just wanted some feedback.

There are 2 non-negative integers: i and j. Gi

21条回答
  •  感情败类
    2020-12-22 15:59

    Use a Min-heap.

    Put 1.

    extract-Min. Say you get x.

    Push 2x and 5x into the heap.

    Repeat.

    Instead of storing x = 2^i * 5^j, you can store (i,j) and use a custom compare function.

提交回复
热议问题