This is not a difficult one.

Basic idea is, assum that we have a self-sorted queue. Everytime, we choose the smallest one *n*, insert 2*n , 3*n , 5*n into this queue. After n times, we will get the n-th Ugly number.

The time will be $O(nlogn)$. Do we have a better way? The answer is YES!