id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n // Function to generate all possible subsets of the array\nvoid generate(vector<vector<int>>& all, vector<int>& temp, vector<int>& nums, int x) {\n all.push_back(temp);\n for (int i = x; i < nums.size(); i++) {\n temp.push_back(nums[i]);\n generate(all, te... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int cnt = 0 ;\n vector<int> v;\n vector<vector<int>> res;\n void dfs(int idx,vector<int>& nums){\n if(idx == nums.size()){\n return;\n }\n for(int i = idx; i < nums.size(); i++){\n v.push_back(nums[i]);\n res.push... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int res = 0;\n\n bool isBeautiful(const vector<int>& curr, int k) {\n int n = curr.size();\n for (int i = 0; i < n; ++i) {\n for (int j = i + 1; j < n; ++j) {\n if (abs(curr[j] - curr[i]) == k) {\n return false;\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubsets(vector<int>& nums, int k) {\n vector<vector<int>> ans;\n vector<int> temp;\n unordered_map<int, int> mp;\n f(0, nums, k, temp, ans, mp);\n return ans.size() - 1; \n }\n\n void f(int index, vector<int>& nums, int k,... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n void helper(vector<int>& nums, vector<int> prev, int idx, int k, int& ans ){\n \n if(idx >= nums.size()){\n return;\n }\n // 1,2,4,5, 7, 10 \n \n // 2, 4, 7, \n // 4\n for(int st = idx; st < nums.size(); st++){\n ... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int res = 0;\n int beautifulSubsets(vector<int>& nums, int k) {\n unordered_multiset<int> valueMap;\n recuSubset(nums, k, valueMap, 0);\n return res;\n }\n\n void recuSubset(vector<int> nums, int k, unordered_multiset<int> &valueMap, int index) {... |
2,696 | <p>You are given an array <code>nums</code> of positive integers and a <strong>positive</strong> integer <code>k</code>.</p>
<p>A subset of <code>nums</code> is <strong>beautiful</strong> if it does not contain two integers with an absolute difference equal to <code>k</code>.</p>
<p>Return <em>the number of <strong>n... | 3 | {
"code": "class Solution {\npublic:\n int solve(int index,vector<int> &nums,int k,vector<int> curr)\n {\n if(index==nums.size())\n {\n if(curr.size()>0)\n return 1;\n else\n return 0;\n }\n int ans=0;\n if(curr.size()>0)\n ... |
263 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="e... | 0 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if(n==0)\n return false;\n while (n != 1) {\n if (n % 2 == 0)\n n = n / 2;\n else if (n % 3 == 0)\n n = n / 3;\n else if (n % 5 == 0)\n n = n / 5;\n ... |
263 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="e... | 0 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if (n <= 0) return false;\n\n while (n % 2 == 0) n /= 2;\n while (n % 3 == 0) n /= 3;\n while (n % 5 == 0) n /= 5;\n\n return n == 1;\n }\n};",
"memory": "7300"
} |
263 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="e... | 0 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if(n<=0){\n return false;\n }\n while(n%2==0){\n n/=2;\n } \n while(n%3==0){\n n/=3;\n }\n while(n%5==0){\n n/=5;\n }\n if(n>1){\n return false;\n... |
263 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="e... | 0 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if(n==0)\n return false;\n int a[3]={2,3,5};\n for(int i=0;i<3;i++){\n while(n % a[i]==0){\n n=n/a[i];\n }\n if(n==1){\n return true;\n }\n }\n retur... |
263 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="e... | 1 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if(n<=0) return false;\n while(n%2==0) n/=2;\n while(n%3==0) n/=3;\n while(n%5==0) n/=5;\n return n==1;\n }\n};",
"memory": "7500"
} |
263 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <code>true</code> <em>if</em> <code>n</code> <em>is an <strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="e... | 1 | {
"code": "class Solution {\npublic:\n bool isUgly(int n) {\n if (n <= 0) return false; // Ugly numbers are positive integers\n \n // Divide n by 2, 3, and 5 as much as possible\n while (n % 2 == 0) n /= 2;\n while (n % 3 == 0) n /= 3;\n while (n % 5 == 0) n /= 5;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "const int res[1691] = {0,1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36,40,45,48,50,54,60,64,72,75,80,81,90,96,100,108,120,125,128,135,144,150,160,162,180,192,200,216,225,240,243,250,256,270,288,300,320,324,360,375,384,400,405,432,450,480,486,500,512,540,576,600,625,640,648,675,720,729,750,768,800,810... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n <= 0) {\n return 0; // Invalid input\n }\n\n int uglyNumbers[n];\n uglyNumbers[0] = 1;\n\n int idx2 = 0, idx3 = 0, idx5 = 0; // Pointers for 2, 3, and 5\n int nextMultiple2 = 2, nextMultip... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int arr[n+1];\n arr[1]=1;\n int i2=1,i3=1,i5=1;\n for(int i=2;i<=n;i++){\n int num1=arr[i2]*2;\n int num2=arr[i3]*3;\n int num3=arr[i5]*5;\n int mini=min({num1,num2,num3});\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int arr[n];\n arr[0]=1;\n int i1=0;int i2=0;int i3=0;\n int a,b,c,m;\n for(int j=1;j<n;j++){\n a=arr[i1]*2;\n b=arr[i2]*3;\n c=arr[i3]*5;\n m=min(a,b);\n m=m... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "#include <bits/stdc++.h>\n#pragma GCC optimize (\"Ofast\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native\")\nusing namespace std;\n#define all(x) x.begin(), x.end()\n\n\nusing ull = unsigned long long;\nusing ll = long long;\n\ninline int gcd(int a,int b) { if (b==0) return... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "#define ll long long\n\nclass Solution {\npublic:\n vector<ll> f = {5,3,2};\n bool is_exact(ll n,ll f){\n if(n==1) return false;\n while(n%f==0) n/=f;\n return n==1;\n }\n vector<map<ll,ll>> memo;\n\n ll gf(ll n,ll it){\n // if(memo[it].find(n)!=memo[it].end()) ret... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "vector<long long int> func(){\n priority_queue<long long int, vector<long long int>, greater<long long int>> pq;\n pq.push(1);\n set<long long int> res;\n res.insert(1);\n while(res.size() < 2000){\n long long int top = pq.top();\n pq.pop();\n if(res.insert(top*2).second... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n \n if(n <= 0)\n {\n return 0;\n }\n else if(n == 1)\n {\n return 1;\n }\n\n int l1 = 0, l2 = 0, l3 = 0;\n int dp[2000] = {0};\n dp[0] = 1;\n\n for(i... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "bool f = 1;\nvector<int> ugly(2,-1);\nvector<int> ans;\ntypedef long long ll;\nbool check(ll n){\n ll i = 2;\n while(i*i<=n){\n if(n%i==0){\n if(i==2 || i==3 || i==5){\n while(n%i==0)n/=i;\n }\n else return 0;\n }\n i++;\n }\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int dp[1691];\n int helper(int n, int i, int a, int b, int c){\n if(i==n) return dp[n-1];\n int x = dp[a]*2, y = dp[b]*3, z = dp[c]*5;\n\n dp[i] = min({x,y,z});\n\n if(dp[i]==x) a++;\n if(dp[i]==y) b++;\n if(dp[i]==z) c++;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> dp(n+1,-1);\n dp[0]=1;\n int l1=0;\n int l2=0;\n int l3=0;\n for(int i=1;i<n;i++){\n int mini=min({dp[l1]*2,dp[l2]*3,dp[l3]*5});\n dp[i]=mini;\n if (mini == dp[... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 0 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> dp(n+1,-1);\n dp[0]=1;\n int l1=0;\n int l2=0;\n int l3=0;\n for(int i=1;i<n;i++){\n int mini=min({dp[l1]*2,dp[l2]*3,dp[l3]*5});\n dp[i]=mini;\n if (mini == dp[... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) \n {\n int a = 1, b = 1, c = 1;\n\n vector<int> arr(n + 1);\n arr[1] = 1;\n\n for(int i = 2;i <= n;i++)\n {\n int x = arr[a] * 2; \n int y = arr[b] * 3; \n int z = arr[c] * 5;\n\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> ugly(n);\n ugly[0] = 1;\n\n int a = 0, b = 0, c = 0;\n for(int i=1; i<n; i++) {\n int curr = min(ugly[a]*2, min(ugly[b]*3, ugly[c]*5));\n if(curr == ugly[a]*2) {\n ugly[i... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<pair<int, int>> index_of_multipliers = {{0, 2}, {0, 3}, {0, 5}};\n vector<long long> candidates = {2, 3, 5};\n vector<int> ugly_numbers = {1};\n ugly_numbers.reserve(n);\n\n for (int i = 1; i < n; ++i) {\n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n /**\n * Dynamic Programming (Tabulation)\n *\n * Track the next multiples of 2, 3, and 5.\n * Select the smallest multiple as the next ugly number.\n * Increment the index for the chosen multiple.\n *\n * Time Complexity: O(n)\n * Space Complex... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "// TC - O(n logn) time - By channa sir\nclass Solution1 {\npublic:\n int nthUglyNumber(int n) {\n set<int> fringeSet;\n fringeSet.insert(1);\n while(n > 1) {\n n--;\n int num = *fringeSet.begin(); // next ugly number\n fringeSet.erase(num);\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 1 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long> arr(n + 1);\n \n arr[0] = 1;\n \n int t2 = 0, t3 = 0, t5 = 0;\n \n for (int i = 1; i <= n; i++) {\n arr[i] = min(arr[t2] * 2, min(arr[t5] * 5, arr[t3] * 3));\n if ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long long> uglies(n);\n uglies[0] = 1;\n \n int i2 = 0, i3 = 0, i5 = 0;\n long long multi2 = 2;\n long long multi3 = 3;\n long long multi5 = 5;\n long long uglies1;\n \n for (int i = 1; i < n; ++i) {\n u... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n#define ll long long\n int nthUglyNumber(int n) {\n vector<int>primes{2,3,5};\n int p=primes.size();\n ll inf=LLONG_MAX;\n vector<ll>vpidx(p,0);\n vector<ll>val(n);\n val[0]=1;\n for(int i=1;i<n;i++){\n ll v=inf;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#define lli long long int \n#define ld long double\n#define vi vector<int>\n#define vlli vector<lli>\n#define vpii vector<pair<int, int>>\n#define pb push_back \n\ntemplate<typename T> void debug(T _a) {cout << _a << \" \";}\ntemplate<typename T1, typename T2> void debug(pair<T1, T2> _p) {cout<<\"{\";debug... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector <long long> primes={2,3,5};\n vector <long long> mulIdx(3,1);\n vector <long long> dp(n+1,0);\n dp[1]=1;\n for (int i=2;i<=n;i++) {\n long long mini=INT_MAX;\n for (int j=0;j<3;j++) {... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> arr;\n arr.push_back(1);\n int i = 1;\n int tw = 0, thr = 0, fv = 0;\n while(i <= n){\n int ans = min({2*arr[tw], 3*arr[thr], 5*arr[fv]});\n if(2*arr[tw] == ans)\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> nums = {1};\n int i2 = 0, i3 = 0, i5 = 0;\n for(int i = 0; i < n; i++) {\n int next_num = min(min(nums[i2] * 2, nums[i3] * 3), nums[i5] * 5);\n nums.push_back(next_num);\n if (next_... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long, vector<long>, greater<long>> pq;\n pq.push(1);\n\n long rval;\n for (int i=0; i<n; i++){\n rval=pq.top();\n pq.pop();\n if (rval%3!=0 && rval%5!=0) pq.push(rval*2);\... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<int64_t, std::vector<int64_t>, std::greater<int64_t>> que;\n que.push(1);\n for (int i = 1; i < n; ++i) {\n int64_t x = que.top();\n que.pop();\n if (x % 3 && x % 5 && x * 2 < 1e... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nint nthUglyNumber(int n) {\n vector<int> store;\n store.push_back(1);\n\n unordered_map<int, int> mp;\n mp[2] = 1;\n mp[3] = 1;\n mp[5] = 1;\n\n while (store.size() != n) {\n int mini = INT_MAX;\n\n \n for (const auto &i : mp) {\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n==1) return 1;\n priority_queue<long long,vector<long long>,greater<long long> > l1,l2,l3;\n l1.push(2);\n l2.push(3);\n l3.push(5);\n \n for (int i = 1 ; i < n - 1; i++)\n {\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n void func(int pt1, int pt2, int pt3, vector<int>& ans, int n) {\n if (ans.size() == n)\n return;\n\n int op1 = ans[pt1] * 2;\n int op2 = ans[pt2] * 3;\n int op3 = ans[pt3] * 5;\n int mini = min({op1, op2, op3});\n\n ans.pus... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> dp(1691);\n dp[0] = 1;\n int a=0,b=0,c=0;\n for(int i=1; i<n; i++){\n dp[i] = min(dp[a]*2, min(dp[b]*3, dp[c]*5));\n if(dp[i] == dp[a]*2) a++;\n if(dp[i] == dp[b]*3) b++;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<int>pq;\n for(int i = 0;i<33;i++){\n for(int j = 0;j<33;j++){\n for(int k = 0;k<33;k++){\n long long number = pow(2,i);\n if(number > INT_MAX){\n break;... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base :: sync_with_stdio(false);\n }\n int nthUglyNumber(int n) {\n priority_queue<int>pq;\n for(int i = 0;i<33;i++){\n for(int j = 0;j<33;j++){\n for(int k = 0;k<33;k++){\n long long number = pow(2,i... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n map<int , int > m;\n m[2]=0;\n m[3]=0;\n m[5]=0;\n vector<int > sub;\n sub.push_back(1);\n int c=1;\n \n int ans=1;\n if (n==c) return c;\n while(n!=c){\n if (... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n #define ll long long\n int nthUglyNumber(int n) {\n vector<int> primes = {2,3,5};\n vector<ll> v(n, 0);\n priority_queue<pair<ll, pair<ll, ll>> ,vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> pq;\n v[0] = 1;\n for(auto ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n queue<int> q2;\n queue<int> q3;\n queue<int> q5;\n\n q2.push(1);\n q3.push(1);\n q5.push(1);\n\n int number = 1;\n int prev = 0;\n while (n > 1) {\n number = min(q2.front(),... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#define ll long long\n\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<ll,vector<ll>,greater<ll>>pq;\n // ll temp2 = 2,temp3 = 3,temp5 = 5;\n // ll idx2 = 2,idx3 = 2,idx5 = 2;\n ll ans;\n pq.push(1);\n ll cnt = 1;\n while( cnt <= ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long long int,vector<long long int>,greater<long long int>> pq;\n pq.push(1);\n for(int i=0;i<n-1;i++){\n long long int val = pq.top();\n // cout<<val<<endl;\n pq.pop();\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long long, vector<long long>, greater<long long>> minHeap;\n minHeap.push(1);\n int count =1;\n long long last_min = 0;\n\n while (count < n){\n \n long long min_num = minHeap... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<pair<long long ,int>, vector<pair<long long,int>>, greater<pair<long long,int>>> pq;\n pq.push({1,1});\n while(n-1) {\n pair x = pq.top();\n pq.pop();\n if(x.second == 1) {\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n == 1) return 1;\n priority_queue<long long, vector<long long>, greater<long long>> two;\n priority_queue<long long, vector<long long>, greater<long long>> three;\n priority_queue<long long, vector<long long>, grea... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nint nthUglyNumber(int n) \n{\n vector<long long int> alpha = {1};\n for(int i = 2;i<=n;i++)\n {\n long long int curUgly = INT_MAX;\n for(auto j : alpha)\n {\n if(j*2>alpha.back()) curUgly = min(curUgly,j*2);\n if(j*3>alpha.back(... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\nint nthUglyNumber(int n) \n{\n vector<long long int> alpha = {1};\n int start = 0;\n for(int i = 2;i<=n;i++)\n {\n long long int curUgly = INT_MAX;\n for(int j = start; j<alpha.size();j++)\n {\n if(alpha[j]*2>alpha.back()) curUgly = min... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "typedef long long int ll;\n\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n const ll two = 2, three = 3, five = 5;\n \n vector<ll> A = {1,2,3,4,5};\n // 0 1 2 3 4\n // first case [1,5]\n if( n <= 5 ) return A[n-1];\n\n int x = 2, y ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long> nums = {1};\n vector<int> factors = {2, 3, 5};\n vector<int> indexes(3, 0);\n vector<long> candidates(3, 0);\n\n for (int i = 1; i < n; ++i) {\n for (int j = 0; j < 3; ++j)\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int>ugly{0};\n priority_queue<int, vector<int>, greater<int>>pq;\n\n for(int i = 1; i <= n; i++){\n if(i < 6){\n ugly.emplace_back(i);\n pq.push(i * 2);\n pq.push(... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n <= 20) {\n // Faster path for smaller numbers.\n int index = 1;\n for (uint32_t i = 1;; ++i) {\n if (isUgly(i)) {\n if (index == n)\n return i... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n \n int count = 1,idx=1;\n vector<long long> ugly(n+1);\n ugly[0] = 1;\n vector<long long> m2,m3,m5;\n m2.push_back(ugly[0]*2);\n m3.push_back(ugly[0]*3);\n m5.push_back(ugly[0]*5);\n\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int isUgly(priority_queue<long, vector<long>, greater<long> >& pq, int n, int &prev, int &cnt) {\n if(cnt == n) return prev;\n long top = pq.top();\n if(prev == top) pq.pop();\n else{\n cnt++;\n // cout<<top*2<<\" \"<<top*3<<\... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n <= 6)\n return n;\n queue<pair<unsigned, unsigned>> q2, q3;\n queue<unsigned> q5;\n unsigned x = 6;\n int k = 6;\n q2.push({8, 4}); q2.push({10, 5});\n q3.push({9, 3});\n q5.... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#define i64 long long\nclass Solution {\npublic:\n void rec(int n,priority_queue<i64>& q,vector<int>&chk,long long val,i64 ind){\n if(ind>3 || val>=INT_MAX){\n return;\n }\n if(q.size()<=n){\n q.push(val);\n }\n if(q.size()>n){\n q.pop(... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long long>dp(n,-1);\n priority_queue<long long,vector<long long>,greater<long long>>pq;\n pq.push(1);\n int i=0;\n while(!pq.empty() && dp[n-1]==-1)\n {\n long long top=pq.top();\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long long int ,vector<long long int>,greater<long long int>> pq;\n pq.push(1);\n vector<long long int> ans(n,0);\n int i=0;\n int prev=0;\n while(i<n){\n long long int a=pq.top();... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) \n {\n vector<int> uglyNumbers(1,1);\n\n std::queue<long> twoList, threeList, fiveList;\n twoList.push(1);\n threeList.push(1);\n fiveList.push(1);\n\n while ( uglyNumbers.size() < n )\n {\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n)\n {\n std::vector<std::uint64_t> ugly_numbers;\n ugly_numbers.reserve(n);\n std::priority_queue<std::pair<std::uint64_t,std::uint8_t>,std::vector<std::pair<std::uint64_t,std::uint8_t>>,std::greater<>> heap;\n heap.emplac... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<long> ugly;\n Solution(){\n ugly.resize(1691);\n long id2=0, id3=0, id5=0;\n \n ugly[0] = 1;\n for(int i=1; i<1691; i++){\n long t2 = ugly[id2]*2, t3 = ugly[id3]*3, t5 = ugly[id5]*5;\n \n if (t2 < t... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n \n vector<long long> ans(1700);\n ans[1] = 1;\n int p2 = 1; int p3 = 1; int p5 = 1;\n \n for(int i=2; i<1700; i++){\n long num_min = min({ ans[p2]*2, ans[p3]*3, ans[p5]*5 });\n ans[i]... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long, vector<long>, greater<long>>pq;\n pq.push(1);\n vector<int>ugly;\n\n while(ugly.size()<n){\n long curNum=pq.top();\n while(!pq.empty() && pq.top()==curNum)\n pq.... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n void helper(int twos, int threes, int fives, int n, long curr, vector<long>& nums) {\n switch (n) {\n case -1:\n return;\n break;\n case 2:\n for (int i = 0; i <= twos; ++i) {\n nums.... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n queue<long> a, b, c;\n a.push(1);\n b.push(1);\n c.push(1);\n int ans = 1;\n for(int i =1;i<n;i++){\n ans = min(min(a.front()*2, b.front()*3),c.front()*5);\n a.push(ans);\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n queue<long> q2;\n queue<long> q3;\n queue<long> q5;\n q2.push(2);\n q3.push(3);\n q5.push(5);\n\n long ugly = 1;\n long prev = 1;\n\n for (int count = 1; count < n; count++) {\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<long long int>v={1};\n int i = 0;\n void solve(int n) {\n while(v.size()<=(n+200)) {\n long long int x = v[i];\n if(!count(v.begin(),v.end(), (x*2)))\n v.push_back(x*2);\n if(!count(v.begin(),v.end(), (x*3)))\n v.push_bac... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\n vector<int> primes = {2, 3, 5};\n int size = primes.size();\npublic:\n int nthUglyNumber(int n) {\n vector<int> ugs(n + 1, 0); \n vector<int> primes_idx(size, 1);\n\n ugs[1] = 1;\n for (int i = 2; i <= n; i++) {\n vector<int> temp(size, ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n long long int nthUglyNumber(long long int n) {\n priority_queue<long long int, vector<long long int>, greater<long long int>> q;\n q.push(1);\n vector<long long int> op;\n while(op.size()<=n)\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "// use priority_queue to get min and second min\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n if (n <= 3)\n return n;\n vector<long long> Uglys{1, 2, 3};\n vector<long long> Us{1, 2, 3};\n vector<long long> ts{5, 4, 6};\n vector<int> Vs{3, 1, 1};... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n int a=1,b=1,c=1;\n // long long a=1,b=1,c=1;\n int ca=1,cb=1,cc=1;\n vector<int> dp(n+1,1);\n for(int i=2;i<=n;i++)\n {\n vector<int> v={a*2,b*3,c*5};\n sort(begin(v),end(v));\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n priority_queue<long, vector<long>, greater<long>> uglys;\n vector<long> used_vals = {0};\n uglys.push(1);\n long ans = 0;\n\n while (n != 0) {\n ans = uglys.top();\n uglys.pop();\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n \n int nthUglyNumber(int n) {\n vector<int>v={2,3,5};\n priority_queue<long,vector<long>,greater<long>>q;\n vector<long>vv;\n long cur;\n q.push(1);\n vv.push_back(1);\n \n for(int i=0;i<n;i++){\n cur = q.top();\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n struct P {\n long long val;\n int k2;\n int k3;\n int k5;\n };\n\n struct PCompare {\n bool operator()(const P& y, const P& x) const { return x.val < y.val; }\n };\n\n int nthUglyNumber(int n) {\n std::priority_queue<P, st... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> primes = {2, 3, 5}; // Initialize the primes array\n vector<int> indices = {0, 0, 0}; // Initialize indices for multiples of 2, 3, 5\n vector<int> uglyArr(1, 1); // Initialize the ugly number array with 1\n\... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\n public:\n static int nthUglyNumber(int n) {\n vector<int> primes = {2, 3, 5}; // Initialize the primes array\n vector<int> indices = {0, 0, 0}; // Initialize indices for multiples of 2, 3, 5\n vector<int> uglyA... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<int> primes = {2, 3, 5};\n vector<int> indices = {0, 0, 0};\n vector<int> uglyArr(1, 1);\n\n for (int i = 1; i < n; ++i) {\n vector<int> next_uglies = {\n uglyArr[indices[0]] * primes[0]... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n Solution()\n {\n std::priority_queue<std::pair<std::uint64_t,std::uint8_t>,std::vector<std::pair<std::uint64_t,std::uint8_t>>,std::greater<>> heap;\n heap.emplace(1,2);\n int back=-1;\n \n for(int found_numbers=0;found_numbers<1690;++foun... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n if(n==1)\n return n;\n vector<queue<long long>> v;\n queue<long long> q;\n q.push(2);\n v.push_back(q);\n q.pop();\n q.push(3);\n v.push_back(q);\n q.pop();\n q.push(5);\... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<int>ans={1,2,3,4,5,6,8,9,10,12};\n int i=6,j=4,k=4;\n Solution(){\n while(ans.size()<1690){\n if((2*ans[i])<=(3*ans[j]) and (2*ans[i])<=(5*ans[k])){\n ans.push_back(2*ans[i]);\n if((2*ans[i])==(3*ans[j])){\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n // map<int, bool> uglyMap; \n // int count = 0;\n // int i = 1;\n // while ( count < n ) {\n // if ( i == 1 ) {\n // uglyMap[i] = true;\n // } else if ( i%2 == 0 ) {\n // ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#define ll long long\nclass Solution {\n priority_queue<int, vector<int>, greater<int>> pq;\nprivate:\n void preComp(int N){\n int n = N;\n for(ll p=0; p<=n/2 + 1; p++){\n for(ll q=0; q<=n/3 + 1; q++){\n for(ll r=0; r<=n/5 + 1; r++){\n if(1LL*pow... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "#define ll long long\nclass Solution {\n priority_queue<int, vector<int>, greater<int>> pq;\n\nprivate:\n void preComp(int N) {\n ll n = 1LL * N;\n for (ll p = 0; p <= n / 2 + 1; p++) {\n for (ll q = 0; q <= n / 3 + 1; q++) {\n for (ll r = 0; r <= n / 5 + 1; r+... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n \n int nthUglyNumber(int n) {\n \n vector<int> res;\n for(int i=0;i<=32;i++){\n if(i > (log2(INT_MAX)/log2(2))) continue;\n int a = pow(2,i); \n for(int j=0;j<=20;j++){\n if(j > (log2(INT_MAX)/... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "//#define int double\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n long long a,b,c;\n vector<int>v;\n for(int i=0;i<32;i++){\n a=pow(5,i);\n if(a>INT_MAX){\n break;\n }\n for(int j=0;j<32;j++){\n b... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "typedef struct {\n uint val;\n uint cur;\n uint potential[3];\n} ugly;\n\nclass Solution {\n vector <ugly> sequence;\n uint current_l1;\n uint cur_ugly;\npublic:\n ugly create_ugly(uint n) {\n ugly a;\n a.val = n;\n a.cur = 0;\n a.potential[0] = n*2;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n int nthUglyNumber(int n) {\n ll max_k = 2 * (n / 3ll + 1) * n * n;\n\n std::vector<ll> nums;\n for (ll k5 = 1; k5 <= max_k; k5 *= 5) {\n for (ll k3 = 1; k3 <= max_k / k5; k3 *= 3) {\n for (ll k2 = 1; k2 <... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n\n int nthUglyNumber(int n) {\n\n int maxval = std::numeric_limits<int>::max();\n \n std::queue<int> arr2;\n arr2.push(1);\n std::queue<int> arr3;\n arr3.push(1);\n std::queue<int> arr5;\n arr5.push(1);\n\n // std:... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n \n long long cache[50][50][50] = {0};\n \n int nthUglyNumber(int n) {\n vector<int> ugly_numbers = {1};\n \n int i=0, j=0, k=0;\n \n int x = 2123366400;\n \n while (x%2 == 0) {\n i++;\n x/=2;\n ... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n vector<int> getVec(int n){\n long long num=1;\n vector<int> vec;\n while(num<=INT_MAX){\n vec.push_back(num);\n num*=n;\n }\n return vec;\n }\n int nthUglyNumber(int n) {\n if(n==1){\n return 1;\... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n \n int nthUglyNumber(int n) {\n if (n <= 6)\n return n;\n\n int answer = 0;\n int count = 1;\n\n std::vector<int64_t> v2({2});\n std::vector<int64_t> v3({3});\n std::vector<int64_t> v5({5});\n v2.reserve(n);\n v2.reserve(n);\n v2.reserve(n);\n\n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n \n int nthUglyNumber(int n) {\n if (n <= 6)\n return n;\n\n int answer = 0;\n int count = 1;\n\n std::vector<int64_t> v2({2});\n std::vector<int64_t> v3({3});\n std::vector<int64_t> v5({5});\n v2.reserve(n);\n v2.reserve(n);\n v2.reserve(n);\n\n... |
264 | <p>An <strong>ugly number</strong> is a positive integer whose prime factors are limited to <code>2</code>, <code>3</code>, and <code>5</code>.</p>
<p>Given an integer <code>n</code>, return <em>the</em> <code>n<sup>th</sup></code> <em><strong>ugly number</strong></em>.</p>
<p> </p>
<p><strong class="example">Ex... | 2 | {
"code": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n vector<long long> nums;\n deque<long long> test2;\n deque<long long> test3;\n deque<long long> test5;\n test2.push_back(1);\n while (nums.size()!=n){\n long long num = min({\n (!t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.