\x08two standard dp solutions
// three lists:\n    // (1) 1\xd72, 2\xd72, 3\xd72, 4\xd72, 5\xd72, \u2026\n    // (2) 1\xd73, 2\xd73, 3\xd73, 4\xd73, 5\xd73, \u2026\n    // (3) 1\xd75, 2\xd75
    // three lists:\n    // (1) 1\xd72, 2\xd72, 3\xd72, 4\xd72, 5\xd72, \u2026\n    // (2) 1\xd73, 2\xd73, 3\xd73, 4\xd73, 5\xd73, \u2026\n    // (3) 1\xd75, 2\xd75, 3\xd75, 4\xd75, 5\xd75, \u2026\n    \n    // O(n) time, O(n) space \n    int nthUglyNumber(int n) {\n        vector<int> d(n, 0);\n        d[0] = 1;\n        \n        int f2 = 2, f3 = 3, f5 = 5;     // min values for multipy factor 2, 3, 5\n        int ix2 = 0, ix3 = 0, ix5 = 0;  // indexs for min values of f2, f3, f5 \n        \n        for (int i = 1; i < n; ++i) {\n            int minV = min(min(f2, f3), f5);\n            d[i] = minV;\n            \n            if (minV == f2) f2 = 2 * d[++ix2];\n            if (minV == f3) f3 = 3 * d[++ix3];\n            if (minV == f5) f5 = 5 * d[++ix5];\n        }\n        \n        return d[n-1];\n    }\n    \n    // O(n) (might be more) time, O(3n) space\n    int nthUglyNumber1(int n) {\n        queue<int> q1, q2, q3;\n        q1.push(1), q2.push(1), q3.push(1);\n        \n        int m = 0;\n        for (int i = 0; i < n; ++i) {\n            m = min(min(q1.front(), q2.front()), q3.front());\n            if (m == q1.front()) q1.pop();\n            if (m == q2.front()) q2.pop();\n            if (m == q3.front()) q3.pop();\n            q1.push(2*m);\n            q2.push(3*m);\n            q3.push(5*m);\n        }\n        \n        return m;\n    }
[]