An ugly number is a positive integer whose only prime factors are 2, 3, and 5. Given n, return the nth ugly number. Sequence: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, ...
Three-pointer DP: maintain pointers p2, p3, p5 into the ugly number sequence. Next ugly number is min(ugly[p2]*2, ugly[p3]*3, ugly[p5]*5).
- dp[0]=1; p2=p3=p5=0.
- For i from 1 to n-1: next = min(dp[p2]*2, dp[p3]*3, dp[p5]*5).
- Advance each pointer whose product equals next (handle ties to avoid duplicates).
- Time Complexity: O(N)
- Space Complexity: O(N)