id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n #define iterator vector<vector<int>>::iterator\n void sort_count(iterator l, iterator r, vector<int>& count) {\n if (r - l <= 1) return;\n iterator m = l + (r - l) / 2;\n sort_count(l, m, count);\n sort_count(m, r, count);\n for (iterator...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "#define it vector<vector<int>>::iterator\nclass Solution {\n vector<vector<int>> vec;\n void helper(it l, it r, vector<int>& res) {\n if(r-l <= 1)\n return;\n it m = l + (r-l) / 2;\n helper(l, m, res);\n helper(m, r, res);\n for(it i = l, j = m; i < m; i...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> ans;\n vector<int> numsToAns;\n vector<int> prevNumsToAns;\n\n void solve(vector<int>& nums, int l, int r) {\n vector<int> left, right;\n int m, lp = 0, rp = 0, idx = l;\n\n if (l == r) \n return;\n\n m = l + (r - l)...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> ans, index;\n void merge(vector<int> &nums, int s, int mid, int e){\n\n vector<int> left,right;\n for(int i=s; i<=mid; i++){\n left.push_back(index[i]);\n }\n for(int i=mid+1; i<=e; i++){\n right.push_back(index...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n void mergesort(int s,int e,int mid,vector<int>&nums,vector<int>&org,vector<int>&count){\n if(s>=e){\n return ;\n }\n vector<int>left;\n vector<int>right;\n \n for(int i=s;i<=mid;i++){\n left.push_back(org[i]);...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n void mergesort(int s,int e,int mid,vector<int>&nums,vector<int>&org,vector<int>&count){\n if(s>=e){\n return ;\n }\n vector<int>left;\n vector<int>right;\n \n for(int i=s;i<=mid;i++){\n left.push_back(org[i]);...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n\nvector<vector<int> > st;\nvoid build(int i, int lo, int hi, vector<int> &arr){\n if(lo == hi){\n st[i].push_back(arr[lo]);\n return;\n }\n int mid = lo + (hi - lo)/2;\n build(2*i+1, lo, mid, arr);\n build(2*i+2, mid +1 , hi, arr);\n vector<int> v...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Node{\n public:\n Node()\n {\n this->l = 0;\n this->r = 0;\n this->arr = vector<pair<int,int>>();\n }\n\n Node(int l, int r)\n {\n this->l = l;\n this->r = r;\n this->arr.assign(r-l+1,{0,0});\n }\n\n int l;\n int r;\n vector<pair...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n void mergeSort(vector<int>& indices, vector<int>& nums, vector<int>& result, int left, int right) {\n if (right - left <= 1) return;\n\n int mid = left + (right - left) / 2;\n mergeSort(indices, nums, result, left, mid);\n mergeSort(indices, nums, ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> result(n);\n vector<int> indices(n);\n for (int i = 0; i < n; i++) {\n indices[i] = i;\n }\n mergeSort(indices, 0, n, result, nums);\n ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> result(n);\n vector<int> indices(n); // record the index. we are going to sort this array\n for (int i = 0; i < n; i++) {\n indices[i] = i;\n }\n ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> result(n);\n vector<int> indices(n);\n\n for(int i = 0 ; i < n ; ++i){\n indices[i] = i;\n }\n\n mergeSort(indices, 0, n, result, nums);\n ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "#include <vector>\nusing namespace std;\n\nclass Solution {\nprivate:\n void mergeSortAndCount(vector<int>& nums, int start, int end, vector<int>& result, vector<int>& indices) {\n if (start >= end) return;\n \n int mid = start + (end - start) / 2;\n mergeSortAndCount(nums, s...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> result(n,0);\n vector<int> indices(n,0);\n for(int i=0;i<n;i++){\n indices[i] = i;\n }\n mergeSort(nums,0,n-1,result,indices);\n for(...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\n void merge(vector<int>& nums, int l, int mid, int h, vector<int>& result, vector<int>& idx){\n if(l >= h)\n return;\n vector<int>temp;\n int i = l;\n int j = mid + 1;\n int cnt = 0;\n while(i <= mid && j <= h){\n if(nums[...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n \n void count(vector<int>& a, vector<int>& nums, int l1, int r1, int l2, int r2, vector<int>& ans) {\n int j=l2;\n for(int i=l1; i<=r1; i++) {\n while(j<=r2 && nums[a[j]] < nums[a[i]]) {\n j++;\n }\n ans[a[i]] +...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> ans;\n void merge(vector<int> &nums, vector<int> &indexes, int low, int mid, int high){\n int count = 0;\n int i = low, j=mid+1;\n vector<int> mergedArray;\n while(i<=mid && j<=high){\n if(nums[indexes[i]] <= nums[indexes[...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n void merge(vector<int> &nums, int low, int high, vector<int> &hash, vector<int> &indexes)\n{\n int mid = (low + high) / 2;\n int i = low, j = mid + 1;\n vector<int> fake;\n int small = 0;\n while (i <= mid && j <= high)\n {\n if(nums[indexes[i]] > num...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\nvoid merge(int l,int h,vector<pair<int,int>>&v,vector<int>&ans){\n int mid=(l+h)/2;\n vector<pair<int,int>>a,b;\n for(int i=l;i<=h;i++){\n if(i<=mid){\n a.push_back(v[i]);\n }\n else{\n b.push_back(v[i]);\n }\n }\n int ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\nvoid merge(int l,int h,vector<pair<int,int>>&v,vector<int>&ans){\n int mid=(l+h)/2;\n vector<pair<int,int>>a,b;\n for(int i=l;i<=h;i++){\n if(i<=mid){\n a.push_back(v[i]);\n }\n else{\n b.push_back(v[i]);\n }\n }\n int ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "// class Solution {\n// void merge(vector<int>& nums, vector<int>& inx, int s, int mid, int e, vector<int>& res){\n// int i = s, j = mid + 1, inversions = 0;\n// vector<int> tmp;\n\n// while (i <= mid || j <= e) { // merge operation\n// if (i <= mid && (j > e || nums...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n if (nums.empty()) return {};\n vector<int> result(nums.size(), 0);\n vector<pair<int,int>> num_inds;\n for (int i = 0; i < nums.size(); i++) {\n num_inds.push_back({nums[i], i});\n }...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n // Merge Sort\n vector<int> mergeSort(vector<int>& nums, vector<int>& counts, int l, int r)\n {\n if(l == r)\n {\n return {l};\n }\n int mid = (l + r) / 2;\n auto left = mergeSort(nums, counts, l, mid);\n auto right =...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n // Merge Sort\n vector<int> mergeSort(vector<int>& nums, vector<int>& counts, int l, int r)\n {\n if(l == r)\n {\n return {l};\n }\n int mid = (l + r) / 2;\n auto left = mergeSort(nums, counts, l, mid);\n auto right =...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\nvector<int> mergeSort(vector<int>&cnt,vector<int>&nums,int l,int r){\n if(l==r)return {l};\n vector<int>a=mergeSort(cnt,nums,l,(l+r)/2);\n vector<int>b=mergeSort(cnt,nums,(l+r)/2+1,r);\n int i=0,j=0;\n for(int i=0;i<a.size();i++){\n while(j<b.size()&&nums[a[...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n struct ArrayValWithOrigIdx {\n int val;\n int originalIdx;\n\n ArrayValWithOrigIdx(int v, int idx) : val(v), originalIdx(idx) {}\n};\n\n// Function to count smaller numbers after self\nvector<int> countSmaller(const std::vector<int>& nums) {\n if (nums.empty()) re...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n struct viPair {\n int val;\n int originalIdx;\n viPair(int v, int idx) : val(v), originalIdx(idx) {}\n};\n\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n \n if (!n) return vector<int>();\n vector<viPair> newNum...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n struct ArrayValWithOrigIdx {\n int val;\n int originalIdx;\n\n ArrayValWithOrigIdx(int v, int idx) : val(v), originalIdx(idx) {}\n};\n\n// Function to count smaller numbers after self\nvector<int> countSmaller(const std::vector<int>& nums) {\n if (nums.empty()) re...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n \n void merge_sort(int i, int mid, int j, vector <pair <int, int> > &vec, vector <int> &cnt){\n vector <pair <int, int> > v1, v2;\n for (int l=i; l<=mid; l++) v1.push_back(vec[l]);\n for (int l=mid+1; l<=j; l++) v2.push_back(vec[l]);\n\n for (in...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n void merge(vector<pair<int, int>>& nums, int l, int r, vector<int>& ans)\n {\n vector<pair<int, int>> left, right;\n int mid = (l + r)/2;\n\n for(int i = l; i <= mid; i++)\n left.push_back(nums[i]);\n\n for(int i = mid + 1; i <= r; i+...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<pair<int,int>> arr;\n for(int i = 0; i < n; i++){\n arr.push_back({nums[i], i});\n }\n vector<int> counts(n, 0);\n mergeSort(0, n-1, counts, arr)...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\n vector<int> ans;\n void merge_sort(vector<pair<int, int>>& x) {\n\n if (x.size() > 1) {\n vector<pair<int, int>> a, b;\n for (int i = 0; i < x.size() / 2; ++i)\n a.emplace_back(x[i]);\n merge_sort(a);\n for (int i = ...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\n vector<int> ans;\n void merge_sort(vector<pair<int, int>>& x) {\n\n if (x.size() > 1) {\n vector<pair<int, int>> a;\n for (int i = 0; i < x.size() / 2; ++i)\n a.emplace_back(x[i]);\n merge_sort(a);\n vector<pair<int,...
315
<p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nu...
3
{ "code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums);\n\nprivate:\n struct IntAndIndex {\n int value;\n int index;\n\n IntAndIndex( int v, int i ) : value( v ), index( i ) {};\n };\n\n vector<IntAndIndex> myArray;\n vector<int> changes;\n\n void mer...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int carr[26];\n bool mark[26];\n for(int i = 0; i<s.size(); i++)\n carr[s[i]- 'a']++;\n string ans = \"\";\n for(int i = 0; i<s.size(); i++){\n carr[s[i]-'a']--;\n ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int n = s.size();\n int last[26] = {0};\n for (int i = 0; i < n; ++i) {\n last[s[i] - 'a'] = i;\n }\n string ans;\n int mask = 0;\n for (int i = 0; i < n; ++i) {\n ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n vector<bool> seen(26, false); // track visited characters\n vector<int> lastIndex(26, 0); // store last index of each character\n string result = \"\"; // use the result string as a stack\n\n fo...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n vector<bool> seen(26, false); // track visited characters\n vector<int> lastIndex(26, 0); // store last index of each character\n string result = \"\"; // use the result string as a stack\n\n fo...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int len = s.size();\n if(len <= 1) return s;\n int count[26] = {0};\n for (auto x : s) {\n count[x - 'a'] ++;\n }\n bool vis[26] = {0};\n string ans;\n for(int i=0; ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n vector<bool> seen(26, false); // track visited characters\n vector<int> lastIndex(26, 0); // store last index of each character\n string result = \"\"; // use the result string as a stack\n\n fo...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\nstatic auto _ = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n string removeDuplicateLetters(string s) {\n\n int n = s.length();\n\n string result;\n vector<bool> taken(26, fa...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int n=s.size();\n vector<bool> taken(26,false);\n vector<int> lastIndex(26);\n\n for(int i=0 ; i<n ; i++){\n\n char ch=s[i];\n lastIndex[ch-'a']=i;\n }\n\n string resul...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int size = s.size();\n int lptr = 0, rptr = 0;\n\n // vector for character last occu\n vector<int> charLastOcc(26, 0);\n for (int i = 0; i < size; i++) {\n charLastOcc[s[i] - 'a'] = i;\n...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n#define FOR(i,a,n) for(int i = a; i < n; ++i)\n#define FOr(j,a,n) for(int j = a; j >= n; --j)\n#define cin(a , n) FOR(i , 0 , n){cin >> a[i];}\n#define cout(a , n) FOR(i ,0 , n){cout << a[i];cs}ce\n#define speed {cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);}\n#define ce cout...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
0
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int n = s.length() ;\n vector<int> freq(26, 0) ;\n for (char ch : s) {\n freq[ch - 'a'] ++ ;\n }\n vector<char> ans ;\n vector<int> used(26, 0) ;\n for(int i = 0 ; i < n ; ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n vector<int> lastIndex(26,0);\n\n vector<bool> seen(26,false);\n\n stack<char> st;\n for(int i = 0;i<s.length();i++){\n lastIndex[s[i] - 'a'] = i;\n }\n\n for(int i = 0;i<s.length(...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int li[26]{0};\n for (int i = 0;i <s.size(); ++i) {\n li[s[i] - 'a'] = i;\n }\n bool seen[26]{false};\n stack<char> st;\n for (int i = 0;i <s.size(); ++i) {\n int c = s...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int n = s.length();\n string ans = \"\";\n vector<int> lastOcc(26, -1);\n vector<bool> visited(26, false);\n stack<char> st;\n for (int i = n - 1; i >= 0; i--) {\n if (lastOcc[s[i...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n stack<char> st;\n string ans=\"\";\n vector<int> last(26, -1), vis(26, 0);\n for (int i = 0; i < s.size(); i++) {\n last[s[i] - 'a'] = i;\n }\n for (int i = 0; i < s.size(); i++) ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n vector<int> lstind(26,0);\n\n for(int i=0;i<s.size();i++){\n lstind[s[i]-'a']=i;\n }\n\n vector<bool> seen(26,false);\n stack<char> st;\n for(int i=0;i<s.size();i++){\n ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n vector<int>last(26,-1);\n for(int i=0;i<s.length();i++){\n last[s[i]-'a']=i;\n }\n vector<int>visited(26,0);\n stack<char>st;\n for(int i=0;i<s.length();i++){\n if(visi...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
1
{ "code": "// stack + frequency + visited vector\n// push the elements in inc order and if the next ele is smaller remove till the\n// stack is empty or we get smaller than curr, also dont remove the element if\n// the freq comes out tobe 0, dec the freq as we pushing into the stack, and\n// dont push the char if it ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n\n string removeDuplicateLetters(string s) { \n string result;\n\n unordered_map<char, int> lastPos;\n for (int i = 0; i < s.size(); ++i)\n lastPos[s[i]] = i;\n\n for (int i = 0; i < s.size(); ++i)\n {\n cout << result ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n\n string removeDuplicateLetters(string s) { \n string result;\n\n unordered_map<char, int> lastPos;\n for (int i = 0; i < s.size(); ++i)\n lastPos[s[i]] = i;\n\n for (int i = 0; i < s.size(); ++i)\n {\n if (result.empt...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string str) {\n stack<char> s;\n string result;\n\n unordered_map<char, int> indices;\n unordered_set<char> taken;\n for (int i = str.size() - 1; i >= 0; --i) {\n if (!indices.count(str[i])) {\n indices[st...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n string res;\n unordered_map<char, int> lastPosMap;\n for (int i = 0; i != s.size(); ++i) lastPosMap[s[i]] = i;\n unordered_set<char> seen;\n for (int i = 0; i != s.size(); ++i) {\n if (s...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n string res = \"\";\n int n = s.size();\n unordered_map<char, int> mp, last;\n for (int i = 0; i < n; i++) {\n last[s[i]] = i;\n }\n for (int i = 0; i < n; i++) {\n if (...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) \n {\n int n = s.size();\n unordered_map<char, int> last;\n for(int i = 0; i < n; i++)\n last[s[i]] = i;\n \n string st; // Monotonic Increasing stack\n unordered_set<char> used;\...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int n=s.size();\n unordered_map<char,int>mp;\n for(int i=0;i<n;i++)\n {\n mp[s[i]]++;\n }\n vector<bool>vis(26,false);\n stack<char>st;\n for(int i=0;i<n;i++...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n stack<int> st;\n std::map<char, int> frequency;\n vector<bool> visited(26);\n string answer = \"\";\n\n for (int c = 0; c < s.length(); c++){\n\n if (frequency.find(s[c]) == frequency.en...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n int n = s.size();\n\n unordered_map<char,int> lastOccurrence;\n\n for(int i=0;i<n;i++)\n {\n lastOccurrence[s[i]] = i;\n }\n\n vector<bool> inStack(26, false); // To track if a character ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
2
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n \n int n = s.size();\n stack<char> st;\n vector<bool> seen(26,0);\n unordered_map<char,int> last_ind;\n for(int i=0;i<n;i++){\n last_ind[s[i]] = i;\n }\n\n for(int i...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
3
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n stack<char>st;\n unordered_map<char,int>mp;\n for(int i=0; i<s.size(); i++){\n mp[s[i]]++;\n }\n vector<int>vis(26,0);\n for(int i=0; i<s.size(); i++){\n if(vis[s[i]-'a']){\n ...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
3
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n stack<char> st;\n unordered_set<char> seen;\n unordered_map<char,int> last_occurence;\n\n for(int i=0;i<s.size();i++){\n last_occurence[s[i]] = i;\n }\n for(int i=0;i< s.size();i+...
316
<p>Given a string <code>s</code>, remove duplicate letters so that every letter appears once and only once. You must make sure your result is <span data-keyword="lexicographically-smaller-string"><strong>the smallest in lexicographical order</strong></span> among all possible results.</p> <p>&nbsp;</p> <p><strong clas...
3
{ "code": "class Solution {\npublic:\n string removeDuplicateLetters(string s) {\n unordered_set<char> set;\n unordered_map<char, int> m;\n stack<char>st;\n string ans;\n for(int i = 0;i<s.size();i++){\n m[s[i]] = i;\n }\n\n for(int i = 0;i<s.size();i++){...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int n=words.size(),ans=0;\n int bitmask[n];\n for(int i=0;i<n;i++){\n bitmask[i]=0;\n for(auto j:words[i]) bitmask[i]|=(1<<(j-'a'));\n }\n for(int i=0;i<n;i++){\n for...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
0
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n int ans = 0;\n int n = words.size();\n vector<int> num(n);\n\n for (int i = 0; i < n; i++) {\n int su...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
2
{ "code": "class Solution {\nprivate:\n vector<int> wordsIndex[26];\n\n string getUniqueChars(string& str) {\n bool hsh[26] = {0};\n for (int i = 0 ; i < str.length() ; i++) {\n hsh[str[i]-'a'] = true;\n }\n\n string uniqChars;\n for (int i = 0 ; i < 26 ; i++) {\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
2
{ "code": "using Freqs = std::array<uint32_t, 26>;\n\nclass Solution {\npublic:\n int maxProduct(vector<string>& words) {\n std::vector<Freqs> freqs;\n freqs.resize(words.size(), Freqs{});\n for (size_t i = 0; i < words.size(); ++i) {\n for (const char c : words[i])\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int n = words.size(), res = 0;\n unordered_map<string, int> freq;\n for (int i = 0; i < n; i++) {\n if (freq.contains(words[i]))\n continue;\n \n int val = 0;\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int n = words.size(), res = 0;\n unordered_map<string, int> freq;\n for (int i = 0; i < n; i++) {\n if (freq.contains(words[i]))\n continue;\n \n int val = 0;\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n vector<vector<int>> s;\n for(int i=0;i < words.size();i++){\n vector<int> freq(26,0);\n for(int j=0;j < words[i].size();j++){\n freq[words[i][j]-'a']+=1;\n }\n s.p...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int max(int a,int b){\n if(a>b){\n return a;\n } \n return b;\n }\n int maxProduct(vector<string>& words) {\n vector<vector<int>> w;\n int n=words.size();\n\n for(int i=0;i<n;i++){\n vector<int> v(26,-1);\n...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int n = words.size();\n vector<unordered_set<int>> charIndicesMap(26);\n for(int i = 0; i < n; i++){\n for(auto ch : words[i]){\n charIndicesMap[ch-'a'].insert(i);\n }\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n int res=0;\n for(int i=0;i<words.size()-1;i++){\n set<char> st(words[i].begin(),words[i].end());\n for(in...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int ans = 0;\n for(int i=0; i<words.size(); i++){\n unordered_map<char,bool> mp;\n\n for(auto ch : words[i]){\n mp[ch] = true;\n }\n for(int j = i+1; j<words.siz...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n unordered_map<string,vector<int>>mp;\n for(auto i : words){\n mp[i].resize(26,0);\n for(auto j : i){\n mp[i][j-'a'] = 1;\n }\n }\n words = {};\n for(au...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n void fillMap(string s, unordered_map<string, bitset<26>>& mp){\n unordered_map<char, int> occ;\n bitset<26> b;\n for(char c:s){\n if(occ[c]>0) continue;\n b=b.to_ulong()+(1<<(c-'a'));\n occ[c]++;\n }\n mp[...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int n = words.size();\n vector<unordered_set<char>> charSets(n); // Store unique characters for each word\n vector<int> lens(n, 0); // Store lengths of each word\n \n // Create character sets and s...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n unordered_map<int,unordered_map<char,int>>mp;\n for(int i=0;i<words.size();i++){\n for(int j=0;j<words[i].length();j++){\n mp[i][words[i][j]]++;\n }\n }\n int ans=0;\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n bool compareMap(unordered_map<char, int> &mapA, unordered_map<char, int> &mapB){\n for(auto pr: mapB){\n if(mapA.find(pr.first)!=mapA.end())return false;\n }\n return true;\n }\n int maxProduct(vector<string>& words) {\n unordered_...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n bool compareMap(unordered_map<char, int> &mapA, unordered_map<char, int> &mapB){\n for(auto pr: mapB){\n if(mapA.find(pr.first)!=mapA.end())return false;\n }\n return true;\n }\n int maxProduct(vector<string>& words) {\n unordered_...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& w) {\n int maxi = 0; int prod,fl; \n int n = w.size();\n vector<unordered_map<int,int>> m;\n for(int i=0; i<n; i++){\n unordered_map<int,int> m1; \n for(int t=0; t<w[i].size(); t++) m1[w[i][t]]++...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n\n struct Trie{\n map<int, Trie> child;\n bool flag;\n int size;\n Trie() {\n flag = 0;\n size = 0;\n }\n \n void addWord(int mask, int pos, int sz) {\n if(pos == 26) {\n flag = 1;\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n vector<vector<int>> dict(1001,vector<int>(26,0));\n for(int j=0;j<words.size();j++)\n {\n for(int i=0;i<words[j].size();i++)\n {\n char ch= words[j][i];\n dict[j...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n vector<int> lenOfWords;\n\n for(int index = 0;index<words.size();index++) {\n sort(words[index].begin(), words[index].end());\n lenOfWords.push_back(words[index].size());\n } \n\n vec...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\n vector<vector<int>>dp;\n unordered_map<string,int>masking;\npublic:\n Solution(){\n ios_base :: sync_with_stdio(false);\n }\n int solve(vector<string>& words,int start,int end){\n if(start >= end){\n return 0;\n }\n if(dp[start][end] ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n bool common(string& a, string& b) {\n vector<bool> freq(26, false);\n\n for (auto it : a) {\n freq[it - 'a'] = true;\n }\n\n for (auto it : b) {\n if (freq[it - 'a'] == true) {\n return true;\n }\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n \n vector < pair < int, vector <int> > > freq;\n\n for(string s : words) {\n vector <int> count(26, 0);\n\n for( char c : s) {\n count[c-'a']++;\n }\n\n f...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n static bool compareSecond(const pair<pair<int, int>, int>& a, const pair<pair<int, int>, int>& b) {\n return a.second > b.second;\n }\n\n int maxProduct(vector<string>& words) {\n vector<pair<int, int>> len(words.size(), {0, 0}); //fisrt: position, second:...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int maxi=0;\n if(words[0].substr(0,4)==\"nopq\") return 976144;\n for(int i=0;i<words.size()-1;i++){\n string s=words[i];\n unordered_map<char,int> mpp;\n for(int j=0;j<s.size();j+...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n\n bool shareCommon(string s1, string s2){\n for(char c: s1){\n if(s2.find(c)!=string::npos) return false;\n }\n return true;\n }\n\n\n int maxProduct(vector<string>& words) {\n int max = 0;\n for(int i=0; i<words.size(); i++...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\n bool isSafe(string s1, string s2) {\n int mask1 = 0, mask2 = 0;\n\n // Set bits for s1\n for (char c : s1) {\n mask1 |= (1 << (c - 'a'));\n }\n\n // Set bits for s2 and check for common characters\n for (char c : s2) {\n ...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n string printBitwise(int n){\n string ans = \"\";\n while(n){\n ans = to_string(n%2) + ans;\n n = n/2;\n }\n return ans;\n }\n int maxProduct(vector<string>& words) {\n int n = words.size();\n vector<int> va...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n string foo(const std::string s)\n {\n std::string r;\n char m[256] = { 0 };\n for (const auto c : s)\n {\n const auto u = (unsigned char)c;\n if (m[u] == 0)\n {\n m[u] = 1;\n r.push_...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int maxProduct(vector<string>& words) {\n int length = words.size();\n //Get the maximum possible product of two lengths\n vector<Combi> sorted;\n for(int i = 0; i < length-1; i++){\n for(int j = i+1; j < length; j++){\n C...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n\n int checkCommon(vector<bool> a,vector<bool> b){\n for(int i=0;i<26;i++){\n if(a[i] && b[i])return true;\n }\n return false;\n }\n\n int maxProduct(vector<string>& words) {\n int n=words.size();\n vector<vector<bool>> commo...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n bool valid(vector<bool> a, vector<bool> b) {\n for (int i=0;i<26;i++)\n if (a[i] && b[i])\n return false;\n\n return true;\n }\n int max (int a, int b) {\n return a > b ? a:b;\n }\n int maxProduct(vector<string>& word...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int count(string s1,string s2){\n int n1=s1.length();\n int n2=s2.length();\n\n vector<bool> flag(26,false);\n \n for(int i=0;i<s1.size();i++){\n flag[s1[i]-'a']=true;\n }\n for(int i=0;i<s2.size();i++){\n if(flag[s2[i]-'a']){\n retu...
318
<p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <stron...
3
{ "code": "class Solution {\npublic:\n int count(string s1,string s2){\n int n1=s1.length();\n int n2=s2.length();\n\n vector<bool> flag(26,false);\n \n for(int i=0;i<s1.size();i++){\n flag[s1[i]-'a']=true;\n }\n for(int i=0;i<s2.size();i++){\n if(flag[s2[i]-'a']){\n retu...