id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "// Idea: Greedy, Prefix Sum, Binary Search, Sorting\nclass Solution {\npublic:\n // _BinarySearch\n int maxFrequency(vector<int>& nums, int k) {\n std::ranges::sort(nums);\n const auto& a = nums;\n const int n = a.size();\n // create the prefix sum array, for quick range-s...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n countingSort(nums);\n int start = 0;\n long long subarraySum = 0;\n int maxFrequency = 1;\n for (int i = 0; i < nums.size(); i++) {\n int subarrayLength = i - start + 1;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int findBest(int target_idx, int k, vector<int>& nums, vector<long>& prefixSum) {\n int target = nums[target_idx];\n \n int i = 0;\n int j = target_idx;\n int result = target_idx;\n \n while(i <= j) {\n int mid = i +...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n=nums.size();\n int a=0, b=0;\n sort(nums.begin(), nums.end());\n vector<long long> prefix(n,nums[0]);\n for(int i=1; i<n; i++)\n prefix[i]=nums[i]+prefix[i-1];\n int ans=...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& a, int k) \n {\n int n=a.size();\n sort(a.begin(),a.end());\n vector<long long>pre(n+1,0);\n for(int i=0;i<n;i++)\n {\n pre[i+1]=pre[i]+a[i];\n }\n int ans=0,i=0,j=0;\n while(i...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n=nums.size();\n int l=0, r=0;\n sort(nums.begin(), nums.end());\n vector<long long> cumml(n,nums[0]);\n for(int i=1; i<n; i++)\n cumml[i]=nums[i]+cumml[i-1];\n int ans=0;\...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int bSearch(int target_idx, vector<int>& nums, int k, vector<long> &prefixSum) {\n int target= nums[target_idx];\n int l = 0;\n int r = target_idx;\n int best_idx= target_idx;\n while(l<=r) {\n int mid = l+(r-l)/2;\n lo...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int lo =1;\n int hi = n;\n vector<long long int> pre(n);\n long long int p=0;\n for(int i=0;i<n;i++){\n p+=nums[i];...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n vector<long long> pre(nums.size());\n pre[0] = nums[0];\n for(int i = 1; i < nums.size(); i++)\n pre[i] = pre[i - 1] + nums[i];\n long long l = 0, r ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n\n int bSearch(int target_idx, int k, vector<int>&nums, vector<long long>&prefix ){\n\n int target = nums[target_idx];\n\n int left = 0;\n int right = target_idx;\n\n int best_idx = target_idx;\n\n while(left<=right){\n int mid = (...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n unordered_map<int, int> map;\n sort(nums.begin(), nums.end());\n\n int left = 0;\n int maxFreq = 0;\n long long currSum = 0;\n\n for (int right = 0; right < nums.size(); right++) {\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end()); // Step 1: Sort the array\n unordered_map<int, int> freqMap; // Step 2: Hash map to store frequency of elements in the window\n long long sum = 0; // Sum of elem...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end()); // Step 1: Sort the array\n unordered_map<int, int> freqMap; // Step 2: Hash map to store frequency of elements in the window\n long long sum = 0; // Sum of elem...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n vector<int> a;\n sort(nums.begin(),nums.end(), greater<int>());\n int l=0;\n for(int i=0;i<nums.size()-1;i++){\n a.push_back(nums[i]-nums[i+1]);\n }\n for(int i=1;i<a.size();i+...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin() , nums.end());\n vector<int> hash;\n hash.push_back(0);\n for(int i=1 ; i<nums.size() ; i++){\n hash.push_back(nums[i] - nums[i-1]+hash[i-1]);\n }\n int l , r...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "vector<int> fq(1e5+1);\nclass Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n for(int i=0; i<=1e5; i++) fq[i]=0;\n int n=nums.size();\n sort(nums.rbegin(), nums.rend())...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "vector<int> fq(1e5+1);\nclass Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n for(int i=0; i<=1e5; i++) fq[i]=0;\n int n=nums.size();\n sort(nums.rbegin(), nums.rend())...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k){ \n sort(nums.begin(), nums.end());\n unordered_map<long, long> freqMap;\n long long left = 0, maxFreq = 0;\n long long total = 0;\n\n for (long right = 0; right < nums.size(); ++right) {\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n vector<int> f(vector<int>& a, vector<long long>& p, long long k) {\n int n = a.size();\n vector<int> res(n, -1);\n\n auto check = [&](int i, int j) {\n long long sum = p[i] - (j > 0 ? p[j - 1] : 0);\n return (long long)a[i] * (i - j ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n // Helper function to check if it's possible to make 'mid' elements equal to nums[i] with k operations\n bool isPossible(vector<int>& nums, int k, int i, int mid, vector<long long>& prefixSum) {\n int startIdx = i - (mid - 1);\n long long sumNeeded = static_c...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n // Function to find the appropriate index using binary search\n int bs(int i, int j, int k, vector<int>& nums, vector<long long>& prefixSum) {\n int left = 0, right = j, idx = j;\n while (left <= right) {\n int mid = (left + right) / 2;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end(), greater<int>());\n unordered_map<int, int> freqmap;\n for (auto val : nums)\n {\n freqmap[val]++;\n }\n int i = 0;\n int temp = k;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n unordered_map<int,int>mp;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n }\n int i=0;\n int co=INT_MIN;\n int cot=0; //count addit...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n=nums.size();\n unordered_map<int,int> mpp;\n sort(nums.begin(),nums.end());\n long long int ans=1;\n long long int i=0;\n long long int j=0;\n long long int temp=0;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n unordered_map<int,int>mpp;\n \n for(int i=0;i<nums.size();i++)\n {\n mpp[nums[i]]++;\n }\n \n sort(nums.begin(),nums.end());\n \n int i=mpp[nums[0]];\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(),nums.end());\n map<int,int>mp;\n long long ans=1,temp=0,sum=0,i=0,j=0,n=nums.size();\n while(j<n){\n sum+=nums[j];\n mp[nums[j]]++;\n temp=(j-i+1)*nu...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
0
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<int> arr(26,0);\n\n int count = 0;\n for(auto it: sentence){\n int index= it - 'a';\n if(arr[index]==0){\n arr[index]++;\n count++;\n }\n ...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
0
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<char>res(26,0);\n for(int i = 0; i < sentence.size();i++){\n res[sentence[i] - 'a']++;\n }\n \n for(int i = 0; i < 26; i++){\n if(res[i] == 0) return false;\n }\n return true;\n...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
1
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<bool>alpha(26,0);\n for(int i=0;i<sentence.size();i++){\n alpha[sentence[i]-'a']=1;\n }\n\n for(int i=0;i<26;i++){\n if(alpha[i]==0)\n return 0;\n }\n\n ...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
1
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n vector<char>res(26,0);\n for(int i = 0; i < sentence.size();i++){\n res[sentence[i] - 'a']++;\n }\n \n for(int i = 0; i < 26; i++){\n if(res[i] == 0) return false;\n }\n return true;\n...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
2
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n std::set<char> seen;\n \n for (char c : sentence) {\n seen.insert(c);\n }\n \n return seen.size() == 26;\n }\n};", "memory": "8100" }
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
2
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n \n set<char>st;\n for(int j=0;j<sentence.size();j++){\n st.insert(sentence[j]);\n }\n if(st.size()==26) return true;\n else return false;\n }\n\n};", "memory": "8100" }
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
2
{ "code": "class Solution \n{\npublic:\n bool checkIfPangram(string sentence)\n {\n unordered_set<char> set;\n \n for(char c : sentence)\n {\n if(set.find(c) == set.end())\n {\n set.insert(c);\n }\n \n if(set.size(...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
2
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n std::set<char> myset = {};\n for (char& c : sentence) {\n myset.insert(c); \n }\n if(myset.size() < 26) {\n return false;\n }\n return true; \n }\n};", "memory": "820...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n std::unordered_set<char> set;\n for(int i = 97; i <= 122; i++)\n set.insert(i);\n\n for(const auto& c : sentence)\n {\n set.erase(c);\n }\n return set.size() == 0;\n }\...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n std::unordered_set<char> set;\n for(int i = 97; i <= 122; i++)\n set.insert(i);\n\n for(const auto& c : sentence)\n {\n set.erase(c);\n }\n return set.size() == 0;\n }\...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n std::unordered_set<char> set;\n for(int i = 97; i <= 122; i++)\n set.insert(i);\n\n for(const auto& c : sentence)\n {\n set.erase(c);\n }\n return set.size() == 0;\n }\...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) \n {\n std::map<char, int> alphabetMap = {};\n \n for(char c : sentence)\n {\n if(alphabetMap.find(c) == alphabetMap.end())\n {\n alphabetMap[c] = 1;\n }\n ...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n int mia(char e){\n string alpha=\"abcdefghijklmnopqrstuvwxyz\";\n for(int i=0;i<alpha.size();i++){\n if(alpha[i]==e){\n return i;\n }\n }\n return -1;\n }\n bool checkIfPangram(string sentence) {\n ...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "using namespace std;\nclass Solution {\npublic:\n bool checkIfPangram(string sentence) {\n unordered_map<char,int> charMap;\n for (int i=0; i<sentence.size(); i++)\n {\n charMap[sentence[i]]++;\n }\n if( charMap.size() == 26) return true;\n else retur...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n int n = sentence.length();\n unordered_map<char, int> mp;\n for (char c : sentence) {\n if (c >= 'a' && c <= 'z') {\n mp[c]++;\n }\n }\n\n for (char c = 'a'; c <= ...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n unordered_set<char> seen(sentence.begin(), sentence.end());\n return seen.size()==26;\n }\n};", "memory": "9100" }
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sen) {\n unordered_map<char,int>mp;\n int n = sen.length();\n for(int i=0; i<n;i++){\n mp[sen[i]++];\n }\n for(int i='a'; i<='z'; i++){\n cout<<i;\n if(mp.find(i)==mp.end()){\n ...
1,960
<p>A <strong>pangram</strong> is a sentence where every letter of the English alphabet appears at least once.</p> <p>Given a string <code>sentence</code> containing only lowercase English letters, return<em> </em><code>true</code><em> if </em><code>sentence</code><em> is a <strong>pangram</strong>, or </em><code>false...
3
{ "code": "class Solution {\npublic:\n bool checkIfPangram(string sentence) {\n unordered_map<int,int>mpp;\n for(int i=0;i<sentence.length();i++){\n mpp[sentence[i]]++;\n }\n if(mpp.size()==26) return true;\n else return false;\n }\n};", "memory": "9200" }
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "class Solution {\npublic:\n vector<int> getAllElements(TreeNode *root1, TreeNode *root2) {\n vector<int> result;\n stack<TreeNode *> st1, st2;\n while (root1) {\n st1.push(root1);\n root1 = root1->left;\n st1.top()->left = nullptr;\n }\n ...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "class Solution {\npublic:\n int partials[2][5001], partialsPos[2] = {0, 0};\n void dfs(TreeNode* root, bool isSecond = false) {\n if (!root) return;\n dfs(root->left, isSecond);\n partials[isSecond][partialsPos[isSecond]++] = root->val;\n dfs(root->right, isSecond);\n }...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "class Solution {\npublic:\n static vector<int> getAllElements(TreeNode* root1, TreeNode* root2) {\n vector<int> res;\n res.reserve(5000 * 2);\n function<void(TreeNode*)> dfs = [&](TreeNode* node) {\n if (node == nullptr) {\n return;\n }\n ...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "\nclass Solution {\npublic:\n vector<int> getAllElements(TreeNode* root1, TreeNode* root2) {\n vector<int> list1, list2;\n inOrderTraversal(root1, list1);\n inOrderTraversal(root2, list2);\n \n // Merge the two sorted lists\n vector<int> result;\n mergeSo...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
0
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
1
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
2
{ "code": "class Solution {\npublic:\n vector<int> ans;\n\n void inorder(TreeNode* root) {\n if(!root) return;\n inorder(root->left);\n ans.push_back(root->val);\n inorder(root->right);\n }\n vector<int> getAllElements(TreeNode* root1, TreeNode* root2) {\n inorder(root1)...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
2
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
2
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,427
<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2019/12/18...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n bool check(vector<int>& arr, int s, int ind) {\n if (ind < 0 || ind >= arr.size() || arr[ind] == -1) return false;\n if (arr[ind] == 0) return true;\n\n int jump = arr[ind];\n arr[ind] = -1; \n\n \n bool canReachLeft = check(arr, s, i...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n if (start >= 0 && start < arr.size() && arr[start] >= 0) {\n if (arr[start] == 0) return true;\n arr[start] = -arr[start];\n return canReach(arr, start + arr[start]) || \n canRea...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n\n bool canReach(vector<int>& arr, int start) {\n //Recursive Approach\n // if(start<0 || start>=arr.size()){\n // return false;\n // }\n // if(arr[start]==0){\n // return true;\n // }\n // return canReach(arr,sta...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n // int i=lower_bound(arr.begin(),arr.end(),0) -;\n //cout<<i<<endl;\n stack<int>st;\n int n=arr.size();\n vector<bool>vis(n,0);\n\n st.push(start);\n\n while(!st.empty())\n {\n ...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<bool> vis(n,false);\n vis[start] = 1;\n queue<int> q;\n q.push(start);\n while(!q.empty()){\n int curr = q.front();\n q.pop();\n ...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<bool> vis(n,false);\n ...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n queue<int> q {};\n q.push(start);\n while(!q.empty()) {\n int top = q.front();\n q.pop();\n if(arr[top] == 0)\n return true;\n \n if(top +...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
0
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n queue<int>q;\n q.push(start);\n\n while(!q.empty())\n {\n int curr = q.front();\n q.pop();\n\n if(arr[curr] == 0)\n return true;\n \n ...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
1
{ "code": "class Solution {\npublic:\n bool canReach(const std::vector<int>& nums, int start) {\n std::queue<int> q;\n std::vector<bool> visited(nums.size(), false);\n q.push(start);\n\n while (!q.empty()) {\n const auto i = q.front();\n q.pop();\n if (v...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
1
{ "code": "static bool can_reach(vector<int>& arr, vector<int>& visited, int index) {\n if (index < 0 || index >= arr.size() || visited[index]) return false;\n if (arr[index] == 0) return true;\n visited[index] = 1;\n return can_reach(arr, visited, index - arr[index]) || can_reach(arr, visited, index + ar...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
1
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& nums, int start) {\n int n=nums.size();\n vector<int> visited(n,0);\n stack<int> st;\n st.push(start);\n while(!st.empty()){\n int node = st.top();\n st.pop();\n if(nums[node]==0) r...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
1
{ "code": "class Solution {\nprivate:\n bool f(vector<int>&arr,vector<int>&dp,int ind)\n {\n if(ind<0 || ind>=arr.size()||dp[ind]==1)return false;\n if(arr[ind]==0)return true;\n dp[ind]=1;\n return f(arr,dp,ind-arr[ind]) ||f( arr,dp,ind+arr[ind]);\n }\npublic:\n bool canReach(...
1,428
<p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code>&nbsp;index of the array. When you are at index <code>i</code>, you can jump&nbsp;to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach&nbsp;<strong>any</strong> index with value 0.</p>...
1
{ "code": "class Solution {\npublic:\n bool canReach(vector<int>& a, int s) {\n int n=a.size(),x;\n vector<int> v(n);\n queue<int> q;\n q.push(s);\n // v[s]=1;\n while(q.size())\n {\n x=q.front();\n q.pop();\n v[x]=1;\n if...