id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n bool isPrime(int n) {\n if (n <= 1) return false;\n if (n == 2 || n == 3) return true;\n if (n % 2 == 0 || n % 3 == 0) return false;\n\n for (int i = 5; i * i <= n; i += 6) {\n if (n % i == 0 || n % (i + 2) == 0) return false;\n }... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n bool isPrime(int num)\n {\n if(num==1) return false;\n else if(num==2) return true;\n int i=2;\n float div=num;\n while(i<=div)\n {\n if(num%i==0) return false;\n i++;\n div=num/i;\n }\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n int prime(int val) {\n if (val < 2) {\n return false;\n }\n for (int i = 2; i <= sqrt(val); i++) {\n if (val % i == 0) {\n return false;\n }\n }\n return true;\n }\n int maximumPrimeDiffe... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n\n bool isPrime(int n)\n {\n if(n<=1)\n {\n return false;\n }\n for(int i=2;i*i<=n;i++)\n {\n if(n%i==0) return false;\n }\n return true;\n }\n int maximumPrimeDifference(vector<int>& nums) {\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n int minIndex = INT_MAX, maxIndex = INT_MIN;\n for (int i = 0; i < nums.size(); i++) {\n if (isPrime(nums[i])) {\n minIndex = min(minIndex, i);\n maxIndex = max(maxIndex,... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n bool prime(int num) {\n if (num == 2) {\n return true;\n }\n if (num < 2) {\n return false;\n }\n for (int i = 2; i <= sqrt(num); i++) {\n if (num % i == 0) {\n return false;\n }\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 1 | {
"code": "class Solution {\npublic:\n \n bool isprime(int x)\n {\n if(x==1) return false;\n for(int i=2;i<=sqrt(x);i++)\n {\n if((x%i)==0)\n {\n return false;\n }\n }\n return true;\n }\n \n int maximumPrimeDifferenc... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 1 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n bool primes[101];\n for(int i=2;i<=100;i++)primes[i]=1;\n primes[0]=primes[1]=0;\n int first=-1,last=-1;\n for(int i=2;i<=100;i++){\n if(primes[i]==1){\n for(int j=i*... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 1 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n vector<int> sieve(101, 1);\n sieve[1] = 0;\n for(int i = 2;i<=10;i++) {\n for(int j = 2*i;j<=100;j+=i) {\n if(sieve[j] != 0) {\n sieve[j] = 0;\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 1 | {
"code": "class Solution {\nprivate:\n vector<bool> prime;\n void sieve(){\n prime[0] = prime[1] = false;\n\n for(int i = 2; i*i <= 104; i++){\n if(prime[i]){\n for(int j = i*i; j <= 104; j += i){\n prime[j] = false;\n }\n }\n... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n void sieve(int psz,vector<int> &isprime){\n isprime[1]=0;\n for(int i=2;i*i<psz;i++){\n if(!isprime[i])continue;\n for(int j=i*i;j<psz;j+=i){\n isprime[j]=0;\n }\n }\n }\n int maximumPrimeDifference(ve... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n vector<bool> isPrime(101, true);\n isPrime[0] = isPrime[1] = false;\n for(int i = 2; i <= sqrt(100); i++){\n if(isPrime[i]){\n for(int j = i*i; j <= 100; j+=i){\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n vector<bool>isP(101,true);\n isP[0] = isP[1] = false;\n\n for(int p = 2; p * p <= 100; p++){\n if(isP[p]){\n for(int i = p*p; i <= 100; i+=p){\n isP[i] = false;... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "#include <vector>\n#include <unordered_set>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isPrime(int num) {\n static unordered_set<int> prime_set = {\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, \n 53, 59, 61, 67, 71, 73, 79, 83, 89, 97\n };\... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n\n bool isPrime(int n)\n {\n if (n <= 1) \n return false;\n if (n <= 3)\n return true;\n if (n % 2 == 0 || n % 3 == 0)\n return false;\n for (int i = 5; i * i <= n; i += 6)\n if (n % i == 0 || n % (i + ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n vector<bool> primes(101,1);\n primes[0]=primes[1]=0;\n for(int i=2; i<=100; i++){\n if(primes[i]){\n for(int j=i*2; j<=100; j+=i){\n primes[j]=0;\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& arr) \n {\n int n=arr.size();\n int is_prime[105];\n for(int i=0;i<=101;i++)is_prime[i]=1;\n is_prime[0]=0;\n is_prime[1]=0;\n for(int i=2;i<=101;i++)\n {\n if(is_prime[i])\... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\nbool isPrime(int n) {\n if (n < 2) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n int sqrt_n = static_cast<int>(sqrt(n));\n for (int i = 3; i <= sqrt_n; i += 2) {\n if (n % i =... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n fillPrime(100, _setPrime);\n\n int posMin=-1, posMax=-1;\n for(int idx=0; idx<nums.size(); ++idx){\n if(_setPrime.contains(nums[idx])){\n if (posMin==-1) posMin = idx;\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n\n set<int> primes;\n\n void initPrime(int n){\n\n for(int i = 2; i <= n; i++){\n bool isPrime = true;\n for(int j = 2; j <= sqrt(i); j++){\n if(i % j == 0){\n isPrime = false;\n break;\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n set <int> primes ={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};\n int l=-1,h=-1;\n for(int i=0; i<nums.size(); i++){\n if(primes.count(nums[i])){\n h=i... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n set <int> primes ={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};\n int l=-1,h=-1;\n for(int i=0; i<nums.size(); i++){\n if(primes.count(nums[i])){\n h=i... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n int n = nums.size();\n set<int> st = {2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , \n 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97};\n \n int first... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\nprivate:\n bool is_prime(int number)\n {\n if(number == 0 || number == 1)\n {\n return false;\n }\n if(number == 2 || number == 3)\n {\n return true;\n }\n for(int i = 2 ; i <= number/2 ; i++)\n {\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n void is_prime(unordered_set<int> &prime){\n prime.insert(2);\n for(int x=3; x<=100; x++){\n bool flag= true;\n for(int i= 2; i<= (x/2); i++){\n if(x % i ==0){\n flag= false;\n break;\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n // Maximum value can be 100 so store all the prime numbers between 1 to 100.\n bool isPrime(int n) {\n if (n <= 1) return false; \n if (n <= 3) return true; \n if (n % 2 == 0 || n % 3 == 0) return false;\n\n for (int i = 5; i * i <... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n unordered_set<int> getAllPrimes(int n){\n unordered_set<int> s;\n for(int i=2;i<=n;i++){\n bool t = true;\n for(int j=2;j<i;j++){\n if(i%j==0){\n t=false;\n break;\n }\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n\n vector<int> v;\n\n for (int i = 0; i < nums.size(); i++) {\n if(nums[i]==1) continue;\n int flag = 1;\n for (int j = 1; j < nums[i]; j++) {\n if(j==1) continue;\n... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 2 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n\n vector<int> v;\n\n for (int i = 0; i < nums.size(); i++) {\n if(nums[i]==1) continue;\n int flag = 1;\n for (int j = 1; j * j <= nums[i]; j++) {\n if(j==1) contin... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "#include <vector>\n#include <cmath>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isPrime(int n) {\n if (n <= 1) return false;\n if (n <= 3) return true;\n if (n % 2 == 0 || n % 3 == 0) return false;\n for (int i = 5; i * i <= n; i += 6) {\n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n\n vector<int> v;\n\n for (int i = 0; i < nums.size(); i++) {\n if(nums[i]==1) continue;\n int flag = 1;\n for (int j = 2; j*j <= nums[i]; j++) {\n \n ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n int first = 0, last = nums.size() - 1, size = nums.size();\n for (first; first < size; first++) if (prime.count(nums[first])) break;\n for (last; la... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n int N = 100;\n vector<int>spf(N+1);\n for(int i =2;i<=N;i++){\n spf[i] = i;\n }\n for(int i =2;i<=N;i++){\n if(spf[i] == i){\n for(int j = i*i;j<=N;j+=i){... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n int ma = 0;\n for(int i : nums){\n ma = max(ma , i);\n }\n vector<bool> primes(ma + 1 , false);\n\n for(int i=2;i<=ma;i++){\n if(!primes[i]){\n for(int j ... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) {\n int p=*max_element(nums.begin(),nums.end());\n vector<int>seive(p+1,0);\n seive[0]=1,seive[1]=1;\n for(int i=2;i*i<=p;i++){\n if(seive[i]==0){\n for(int j=i*i;j<=p;j+=i){\n... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n bool isPrime(int n){\n if(n == 1) return false;\n for(int i=2;i<n;i++){\n if(n%i == 0) return false;\n }\n return true;\n }\n int maximumPrimeDifference(vector<int>& nums) {\n vector <int> v;\n\n for(int i=0;i<nums.si... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\nbool checkprime(long long n){\n if(n<=1)return false;\n for(int i =2;i*i<=n;i++){\n if(n%i==0){\n return false;\n }\n }\n return true;\n\n}\n int maximumPrimeDifference(vector<int>& nums) {\n vector<int>ans;\n for(int i =0;i<n... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 3 | {
"code": "class Solution {\npublic:\n int maximumPrimeDifference(vector<int>& nums) \n {\n vector<int> arr;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]!=1 && ((nums[i]==2 || nums[i]==3 || nums[i]==5 || nums[i]==7) ||nums[i]%2!=0 && nums[i]%3!=0 && nums[i]%5!=0 && nums[i]%7... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 0 | {
"code": "// ABHI\ntypedef long long int ll;\nclass Solution {\npublic:\n ll count(vector<int>& coins,ll mid){\n ll ans = 0;\n int n = coins.size();\n for(int i=1;i<(1<<n);i++){\n int cnt = __builtin_popcount(i);\n ll g = 1;\n for(int j=0;j<n;j++){\n ... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 0 | {
"code": "class Solution {\npublic:\n long long gcd(long long a,long long b){\n if(a==0)return b;\n if(b==0)return a;\n if(a>b)return gcd(a%b,b);\n return gcd(b%a,a);\n }\n\n void give(long long curr,long long i,long long taken,long long &cnt,vector<int> &coins,long long k){\n ... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 0 | {
"code": "class Solution {\npublic:\n long long cnt(long long n, vector<int>&coins, int k) {\n\n int m = coins.size();\n int s = 1<<m;\n long long total = 0;\n\n for(int i=1; i<s; i++) {\n\n long long l = 1;\n long long cnt = 0;\n\n for(int j=0; j<m; j+... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 0 | {
"code": "#define ll long long int\nclass Solution {\nprivate:\n ll cnt_less_than_eql_x(vector<int>& coins, ll x){\n int midx = coins.size();\n int all_ones = (1 << midx) - 1;\n ll cnt = 0;\n for(int mask = 1; mask <= all_ones; mask++){\n ll set_bits_lcm = 1;\n fo... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n long long lo=1,hi=1e13;\n int n=coins.size();\n while(lo<=hi)\n {\n long long mid=(lo+hi)/2;\n long long count=0;\n long long val=pow(2,n);\n for(l... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "class Solution {\npublic:\n long long lcm(long long a,long long b){\n return (a/__gcd(a,b))*b;\n }\n\n long long chk(long long mid,vector<int>&coins){\n long long n = coins.size();\n long long ans = 0;\n long long cnt;\n for(long long mask = 1;mask<pow(2,n)... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& c, int k) {\n vector<int> a;\n for (auto i : c) {\n int key = 1;\n for (auto j : c)\n if (i > j)\n if (gcd(i, j) == j)\n key = 0;\n if (key)\n a.push_back... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "class Solution {\n vector<long> _processOut(vector<int>& coins) {\n ranges::sort(coins);\n int n = coins.size();\n if (coins[0] == 1) return {1};\n vector<long> longCoins;\n for (int coin: coins) {\n for (int lcoin: longCoins) {\n if (coin % l... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "typedef long long ll;\n\nclass Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n // setup\n sort(coins.begin(), coins.end());\n int n = coins.size(), maskLimit = 1<<n;\n lcmOfMask[0] = 1;\n numberBitOneOfMask[0] = 0;\n for (int mask=... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n \n using ll = long long;\n int n = coins.size();\n vector<ll> mult(1 << n, 1);\n for (int b = 0; b < (1 << n); ++b) {\n for (int i = 0; i < n; ++i) {\n if (b & (1 << i)) {\n ... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n \n using ll = long long;\n int n = coins.size();\n vector<ll> mult(1 << n, 1);\n for (int b = 0; b < (1 << n); ++b) {\n for (int i = 0; i < n; ++i) {\n if (b & (1 << i)) {\n ... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 2 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n //kth smallest integer you can make from coins provided given you cannot combine coins of different denominations\n //note that you have only sums which is multiple of only one ty... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n \n using ll = long long;\n int n = coins.size();\n vector<ll> mult(1 << n, 1);\n for (int b = 0; b < (1 << n); ++b) {\n for (int i = 0; i < n; ++i) {\n if (b & (1 << i)) {\n ... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n bool check(vector<int> v, ll x, int k)\n {\n int n = v.size();\n ll sum = 0;\n for(int i = 1; i < (1 << n); i++)\n {\n ll cnt = 0;\n ll lcm = 1;\n for(int j = 0; j < n; j++)\n {\n... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n long long lcm(long long a, long long b) { return (a * b) / (long long)gcd(a, b); }\n long long min(long long a, long long b) { return a > b ? b : a; }\n long long getPosition(long long int k, vector<int> v, long long int check) {\n // cout << \"---------->>\" << ... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n using ll = long long;\n\n ll lcm(ll a, ll b) {\n ll p = a * b;\n ll t = 0;\n while(b) {\n t = b;\n b = a % b;\n a = t;\n }\n return p / a;\n }\n\n long long findKthSmallest(vector<int>& coins, int k)... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n using ll = long long;\n\n ll lcm(ll a, ll b) {\n ll p = a * b;\n ll t = 0;\n while(b) {\n t = b;\n b = a % b;\n a = t;\n }\n return p / a;\n }\n\n long long findKthSmallest(vector<int>& coins, int k)... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\n bool isPossible(vector<long long>& LCMS, int k, long long mid){\n long long res = 0;\n int n = LCMS.size();\n\n for(int i = 0; i < n; i++){\n res += mid/LCMS[i];\n }\n return res >= k;\n }\n\npublic:\n long long findKthSmallest(vecto... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\n bool isPossible(vector<long long>& LCMS, int k, long long mid){\n long long res = 0;\n int n = LCMS.size();\n\n for(int i = 0; i < n; i++){\n res += mid/LCMS[i];\n }\n return res >= k;\n }\n\npublic:\n long long findKthSmallest(vecto... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n long long lcm(long long a, long long b) {\n return (a / gcd(a, b)) * b;\n }\n\n long long findKthSmallest(vector<int>& coins1, int k1) {\n vector<long long> coins;\n for(auto it: coins1)coins.push_back(it);\n long long k = k1;\n sort(c... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n long long lcm(long long a, long long b) {\n return (a / gcd(a, b)) * b;\n }\n\n long long findKthSmallest(vector<int>& coins1, int k1) {\n vector<long long> coins;\n for(auto it: coins1)coins.push_back(it);\n long long k = k1;\n sort(c... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <numeric> // for gcd\n#include <cmath>\n\nusing namespace std;\n\nclass Solution {\npublic:\n typedef long long ll;\n ll gcd(ll a, ll b) {\n while (b) {\n ll temp = b;\n b = a % b;\n a = tem... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n int n=coins.size();\n vector<vector<long long>> t(n+1);\n\n //calculating lcm\n auto lcm=[&](long long a, long long b){\n return (a*b)/__gcd(a, b);\n };\n //for gener... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n long long findKthSmallest(vector<int>& coins, int k) {\n const int n = static_cast<int>(coins.size());\n const unsigned int max_mask = 1 << n;\n std::vector<std::vector<long> > size_to_lcm(n + 1);\n for (unsigned int mask = 1; mask < max_mask; ++ma... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\n public:\n long long findKthSmallest(vector<int>& coins, int k) {\n const vector<vector<long>> sizeToLcms = getSizeToLcms(coins);\n long l = 0;\n long r = static_cast<long>(k) * ranges::min(coins);\n\n while (l < r) {\n const long m = (l + r) / 2;\n if (numDenominat... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "\nclass Solution {\n public:\n long long findKthSmallest(vector<int>& coins, int k) {\n const vector<vector<long>> sizeToLcms = getSizeToLcms(coins);\n long l = 0;\n long r = static_cast<long>(k) * ranges::min(coins);\n\n while (l < r) {\n const long m = (l + r) / 2;\n if (numDenomin... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, long long>> lcms;\n\n long long gcd(long long a, long long b) {\n if (a < b) {\n long long tmp = a; \n a = b; \n b = tmp;\n }\n while (a % b != 0) {\n long long r = a% b;\n a = b;\... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, long long>> lcms;\n\n long long gcd(long long a, long long b) {\n if (a < b) {\n long long tmp = a; \n a = b; \n b = tmp;\n }\n while (a % b != 0) {\n long long r = a % b;\n a = b;... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, long long>> lcms;\n\n long long gcd(long long a, long long b) {\n if (a < b) {\n long long tmp = a; \n a = b; \n b = tmp;\n }\n while (a % b != 0) {\n long long r = a% b;\n a = b;\... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, long long>> lcms;\n\n long long gcd(long long a, long long b) {\n if (a < b) {\n long long tmp = a; \n a = b; \n b = tmp;\n }\n while (a % b != 0) {\n long long r = a% b;\n a = b;\... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, long long>> lcms;\n\n long long gcd(long long a, long long b) {\n if (a < b) {\n long long tmp = a; \n a = b; \n b = tmp;\n }\n while (a % b != 0) {\n long long r = a% b;\n a = b;\... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "int gcd(int a, int b){\n if(a == 0) return b;\n else if(b == 0) return a;\n if(a == b) return a;\n int mini = min(a, b);\n b = max(a, b);\n a = mini;\n\n return gcd(b%a, a);\n}\n\nclass Solution {\npublic:\n long long findKthSmallest(vector<int>& C, int k) {\n #define int lon... |
3,375 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>k</code>.</p>
<p>You have an infinite number of coins of each denomination. However, you are <strong>not allowed</strong> to combine coins of different denominations.</p>
<p>Return the <code>k<sup>t... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<long long, int>> lcms;\n\n long long gcd(long long a, long long b) {\n if (a < b) {\n long long tmp = a; \n a = b; \n b = tmp;\n }\n while (a % b != 0) {\n long long r = a % b;\n a = b;... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "#include <bits/stdc++.h>\n\nusing namespace std;\ntypedef long long ll;\n#define int ll\n\nconst int N = 1e5 + 1;\nint n;\nint and_tree[2 * N];\nint min_tree[2 * N];\nint dp[2 * N];\n\nfunction<int(int, int)> min_op = [](int a, int b)\n{ return min(a, b); };\nfunction<int(int, int)> and_op = [](int a, int ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "#include <bits/stdc++.h>\n\nusing namespace std;\ntypedef long long ll;\n#define int ll\n\nconst int N = 1e5 + 1;\nint n;\nint and_tree[2 * N];\nint min_tree[2 * N];\nint dp[2 * N];\n\nfunction<int(int, int)> min_op = [](int a, int b)\n{ return min(a, b); };\nfunction<int(int, int)> and_op = [](int a, int ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int n,m;\n int minValue(int start, int part, vector<int>& nums, vector<int>& andValues, vector<vector<int>>& dp){\n\n if(start == n){\n if(part == m) return 0;\n return 1e9;\n }\n if(part == m){\n if((andValues[part - 1... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "#include <bits/stdc++.h>\n#define dbg(x) cout << #x << \": \" << x << endl\n\nconst int INF = 1e9 + 9;\nconst int NEUTRAL = (1LL << 31) - 1;\n\nclass Solution {\npublic:\n\n struct MinDeque {\n stack<pair<int, int>> left, right;\n\n MinDeque() {\n left = stack<pair<int, int>>();... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "\nconst int INF = 0x3f3f3f3f;\nclass Solution {\npublic:\ntemplate<invocable<int,int> Op, int Id>\nstruct SegTree{\n int size;\n vector<int> tr;\n \n SegTree(vector<int> &arr): size(arr.size()), tr(5*size,Id){\n build(arr,1,size,1);\n }\n\n void build(vector<int> &arr, int s, int t... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "constexpr int kBits = 32;\nconstexpr int kInf = numeric_limits<int>::max();\n\nstruct Segtree {\n vector<int> tv;\n\n Segtree(int len) : tv(4 * len, kInf) {}\n\n void Set(int pos, int value, int l = 0, int r = -1, int v = 0) {\n if (!v) r = tv.size() / 4 - 1;\n\n if (l == r) {\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int n ;\n vector<int> tree;\n vector<vector<int>> mintree;\n\n void update(vector<vector<int>>& dp,int size ,int j){\n int w = size;\n for(int i=w;i<2*w;i++) mintree[i][j] = dp[i-w][j];\n for(int i=w-1;i>0;i--) mintree[i][j] = min(mintree[i*2]... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size();\n int m = andValues.size();\n int inf = 1e9+1;\n\n vector<vector<int> > ans(n, vector<int>(m));\n\n map<int, pair<int, int>> dp;\n for (int i = 0;... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n void update(vector<int>& tree, int node, int st, int en, int idx, int val) {\n if (st == en) {\n tree[node] = val;\n return;\n }\n int mid = (st + en) / 2;\n if (idx <= mid) {\n update(tree, 2* node + 1, st, mid, id... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> v;\n vector<vector<int>> t;\n int findRangeAnd(int i,int j)\n {\n int ans=0;\n for(int k=0;k<20;k++)\n {\n if(v[j][k]-(i ? v[i-1][k] : 0)==j-i+1)\n ans|=(1<<k);\n }\n return ans;\n }\... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "void build(int ind,int low, int high, vector<int>&vec_seg, vector<int>&a){\n if(low==high){\n vec_seg[ind] = a[low];\n return;\n }\n int mid = (low+high)/2;\n build(2*ind+1,low,mid,vec_seg,a);\n build(2*ind+2,mid+1,high,vec_seg,a);\n vec_seg[ind] = min(vec_seg[2*ind+1],vec_s... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class SparseTable {\npublic:\n SparseTable(const vector<int>& arr) {\n build(arr);\n }\n\n // Function to build the Sparse Table\n void build(const vector<int>& arr) {\n int n = arr.size();\n int k = log2(n) + 1; // Maximum power of 2 <= n\n\n table.resize(n, vector<... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "typedef long long ll;\ntypedef vector<int> vi;\ntypedef pair<int, int> pi;\nconst ll INF = LONG_LONG_MAX - 1;\n\nclass Solution {\npublic:\n ll highestPowerof2LessThanOrEq(ll x) {\n // check for the set bits\n x |= x >> 1;\n x |= x >> 2;\n x |= x >> 4;\n x |= x >> 8;\n x |= x >> 16;\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "struct RMQ\n{\n int n;\n vector<int> log2;\n vector<vector<int>> rmq;\n void Build(vector<int> &vi)\n {\n n=vi.size();\n log2.assign(n+1,0);\n for(int i=2;i<=n;++i)\n {\n log2[i]=log2[i/2]+1;\n }\n rmq.assign(log2[n]+1,vector<int>(n));\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n// using namespace __gnu_pbds;\n #define vb vector<bool>\n #define ff first\n #define ss second\n #define pb push_back\n #define gout(tno) cout << \"Case #\" << tno++ <<\": \"\n #define ld long double\n #define f(i, a... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "#define ll long long\n#define av andValues\nclass ST{\n public:\n vector<ll>seg;\n ST(int n)\n {\n seg.resize(4*n);\n }\n void build(int ind,int low,int high)\n {\n if(low==high)\n {\n seg[ind]=INT_MAX;\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "#define ll long long\n#define av andValues\nclass ST{\n public:\n vector<ll>seg;\n ST(int n)\n {\n seg.resize(4*n);\n }\n void build(int ind,int low,int high)\n {\n if(low==high)\n {\n seg[ind]=INT_MAX;\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "namespace atcoder {\n\nnamespace internal {\n\n#if __cplusplus >= 202002L\n\nusing std::bit_ceil;\n\n#else\n\n// @return same with std::bit::bit_ceil\nunsigned int bit_ceil(unsigned int n) {\n unsigned int x = 1;\n while (x < (unsigned int)(n)) x *= 2;\n return x;\n}\n\n#endif\n\n// @param n `1 <=... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Node {\npublic:\n Node(int v, Node* l, Node* r) {\n val = v;\n left = l;\n right = r;\n }\n int val;\n Node* left;\n Node* right;\n};\n\nclass SegmentTree {\npublic:\n SegmentTree(vector<int>& nums) {\n len = nums.size() - 1;\n root = createTree(0,... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Node {\npublic:\n Node(int v, Node* l, Node* r) {\n val = v;\n left = l;\n right = r;\n }\n int val;\n Node* left;\n Node* right;\n};\n\nclass SegmentTree {\npublic:\n SegmentTree(vector<int>& nums) {\n len = nums.size() - 1;\n root = createTree(0,... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Node {\npublic:\n Node(int v, Node* l, Node* r) {\n val = v;\n left = l;\n right = r;\n }\n int val;\n Node* left;\n Node* right;\n};\n\nclass SegmentTree {\npublic:\n SegmentTree(vector<int>& nums) {\n len = nums.size() - 1;\n root = createTree(0,... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n const int INF = 1e9 + 7;\n int n = nums.size(), m = andValues.size();\n std::unordered_map<long long, int> memo;\n // k: AND result\n auto dfs = [&](int i, int j, int k, auto... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n const int mx = INT_MAX / 2;\n unordered_map<long long, int> memo;//14 + 4 + 17\n auto dfs = [&](auto&& dfs, int i, int j, int and_) -> i... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int dfs(vector<int>& nums, vector<int>& andValues, int i, int j, int curr, unordered_map<long long, int>& memo){\n if (nums.size() - i < andValues.size() - j) return INT_MAX;\n if (j == andValues.size()) return i == nums.size()?0:INT_MAX;\n curr = curr & ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n vector<vector<map<int,int>>> dp;\n dp.resize(n, vector<map<int,int>> (m));\n\n int currentAndValue = -1;\n for (int i = 0; i < n;... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n unordered_map<long long, long long> memo;//14 + 4 + 17\n auto&& dfs = [&](auto dfs, long long i, long long j, int and_) -> long long{\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n const int mx = INT_MAX / 2;\n unordered_map<long long, int> memo;//14 + 4 + 17\n auto&& dfs = [&](auto dfs, long long i, long long j, in... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n unordered_map<long long, long long> memo;//14 + 4 + 17\n auto&& dfs = [&](auto dfs, long long i, long long j, int and_) -> long long{\n ... |
3,364 | <p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p>
<p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p>
<p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint... | 0 | {
"code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n const int mx = INT_MAX / 2;\n unordered_map<long long, int> memo;//14 + 4 + 17\n auto&& dfs = [&](auto dfs, int i, int j, int and_) -> i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.