Very nice solution. However it is a little misleading to me at the first glance. When trying to understand "every subsequence is the ugly-sequence itself (1, 2, 3, 4, 5, …) multiply 2, 3, 5." I automatically thought the sequence could go on like (1, 2, 3, 4, 5, 6, 7, 8, 9, 10....), it could be better to list it like: (1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15). A minor suggestion.
I find a interesting thing.
If I remove the "static" from your code, the speed will be decreased a lot.
so I think all tests are just running in one main function in leetcode. That means you can use static or global to remember some dp status to speed up your codes.
The chances are repetition is not possible here....even if I am maintaining 3 queues of multiples of 2, 3 and 5 each. Now observe the code is having if-else-if ladder. It's like every time there is a new minimum...moreover if it's from 2's queue I am pushing data in all queues.But if it's from 3's queue I am only pushing data in 3's & 5's queue (not in 2's queue obeserve 23 32 eliminated) just like that in last only pushing in 5's queue(not in 2's & 3's queue to eliminate situations like 35 53 25 52). Everytime bigger minimum will come and due to more restrictive & selective push each queue will be having bigger & distinct elements.
But better use a min priority queue of size 3 for this problem. That will be more easy & short.