id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n static int cmp(pair<int,string>& a, pair<int,string>b){\n return a.first>=b.first;\n }\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<int,string>>p;\n for(int i=0;i<heights.size();i++){\n p.push_b... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<string> res;\n int n=names.size();\n map<int,string> mp;\n for(int i=0;i<n;i++){\n mp[heights[i]]=names[i];\n }\n vector<pair<int,string>> ve... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n int n = names.size();\n unordered_map<int, string> mp;\n vector<pair<int, string>> vec;\n vector<string> ans;\n \n for (int i = 0; i < n; i++) {\n m... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n struct Temp{\n string name;\n int height;\n };\n\n bool static comp(Temp val1, Temp val2){\n return val1.height > val2.height;\n }\n\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n int n = names.size();\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "void quick_sort(vector<pair<int, string>>& v, int low, int high) {\n if (low >= high) {\n return;\n }\n \n auto pivot = v[low];\n int i = low, j = high;\n while (i < j) {\n while (i < j && v[j] >= pivot) j--;\n v[i] = v[j];\n while (i < j && v[i] <= pivot) i++;... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "void quick_sort(vector<pair<int, string>>& v, int low, int high) {\n if (low >= high) {\n return;\n }\n \n auto pivot = v[low];\n int i = low, j = high;\n while (i < j) {\n while (i < j && v[j] >= pivot) j--;\n v[i] = v[j];\n while (i < j && v[i] <= pivot) i++;... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n struct sort_st {\n string name;\n int height;\n };\n bool static cmp(sort_st s1, sort_st s2) { return (s2.height < s1.height); }\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n struct sort_st st[names.size()];\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n\n struct sort_st {\n string name;\n int height;\n };\n bool static cmp(sort_st s1, sort_st s2) { return (s2.height < s1.height); }\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n ios_base::sync_with_stdio(false);\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n\n struct sort_st {\n string name;\n int height;\n };\n bool static cmp(sort_st s1, sort_st s2) { return (s2.height < s1.height); }\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n ios_base::sync_with_stdio(false);\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n void merge(vector<int>& v, int start, int mid, int end) {\n vector<int> left_vector(v.begin() + start, v.begin() + mid + 1);\n vector<int> right_vector(v.begin() + mid + 1, v.begin() + end + 1);\n\n int index = start, i = 0, j = 0;\n\n while (i < l... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n std::vector<std::tuple<std::string, int>> compounds;\n compounds.reserve(names.size());\n for (int i = 0; i < names.size(); ++i) {\n compounds.emplace_back(std::make_tup... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\nprivate:\n static bool comp(pair<int, string> a, pair<int, string> b) {\n return a.first > b.first;\n }\n\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<int, string>> v(names.size());\n for(int i=0;i<names.si... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n unordered_map<string, int> mp;\n\n for (auto& name : names)\n mp[name]++;\n\n vector<pair<int, string>> heightAndNames; \n for (int i = 0; i < names.size(); ++i)\... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n unordered_map<string, int> mp;\n\n for (auto& name : names)\n mp[name]++;\n\n vector<pair<int, string>> heightAndNames; \n for (int i = 0; i < names.size(); ++i)\... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "bool comp(pair<string, int> a, pair<string, int> b){\n return (b.second<a.second);\n}\n\nclass Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<string, int>> temp(names.size());\n for(int i=0; i<names.size(); i++){\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n \n vector<pair<string,int>>v(heights.size());\n for (int i=0; i<heights.size(); ++i) {\n v[i].first = names[i];\n v[i].second = heights[i];\n }\n\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n map<int,string>mp;\n vector<string>ans;\n vector<pair<int,string>>A;\n for(int i=0;i<names.size();i++){\n mp[heights[i]]=names[i];\n }\n for(auto &i... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic: \n static bool cmp(pair<string,int> a, pair<string,int> b){\n return a.second>b.second;\n }\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n int n=names.size();\n vector<pair<string,int>> arr(n);\n\n for(int i=0; i<n... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<string, int>> tp(names.size());\n for(int i{}; i != tp.size(); i++) {\n tp[i] = {names[i], heights[i]};\n }\n sort(tp.begin(), tp.end(), [&](pair<stri... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<string, int>> tp(names.size());\n for(int i{}; i != tp.size(); i++) {\n tp[i] = {names[i], heights[i]};\n }\n sort(tp.begin(), tp.end(), [&](pair<stri... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<string, int>> tp(names.size());\n for(int i{}; i != tp.size(); i++) {\n tp[i] = {names[i], heights[i]};\n }\n sort(tp.begin(), tp.end(), [&](pair<stri... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n \n vector<pair<string,int>>v(heights.size());\n for (int i=0; i<heights.size(); ++i) {\n v[i].first = names[i];\n v[i].second = heights[i];\n }\n\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n int n = names.size();\n vector<pair<string , int>> v(n);\n for (int i = 0; i < n; i++) {\n v[i].first = names[i];\n v[i].second = heights[i];\n }\n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n static bool compare(pair<int,string> a, pair<int,string> b){\n return a.first > b.first;\n }\n \n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n int n = names.size();\n vector<pair<int,string> > v(n);\n \n ... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<people> p;\n people tmp;\n for(int i = 0; i < names.size(); i++){\n tmp.n = names[i];\n tmp.h = heights[i];\n p.push_back(tmp);\n }\n... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "bool cmp (pair <string, int> a, pair <string, int> b) {\n return a.second > b.second;\n }\n\n\n\nclass Solution {\npublic:\n \n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector <pair<string, int>> people;\n for (int i = 0; i < names.size(); i++... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "bool cmp (pair <string, int> a, pair <string, int> b) {\n return a.second > b.second;\n }\n\n\n\nclass Solution {\npublic:\n \n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector <pair<string, int>> people;\n for (int i = 0; i < names.size(); i++... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<int,string>> v;\n for(int i=0;i<names.size();i++){\n v.push_back({heights[i],names[i]});\n }\n\n sort(v.begin(),v.end(),[=](pair<int,string>a , pair<i... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "#include <utility>\n\nclass Solution {\npublic:\n vector<string> sortPeople(vector<string>& names, vector<int>& heights) {\n vector<pair<int,string>> result;\n for(int i=0;i<names.size();i++){\n result.push_back({heights[i],names[i]});\n }\n sort(result.begin(),res... |
2,502 | <p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>
<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <c... | 3 | {
"code": "class Solution {\npublic:\n struct Person {\n string name;\n int height;\n Person(string n, int h) {\n name = n;\n height = h;\n }\n };\n\n static bool compareByHeight(const Person p1, const Person p2) {\n return p1.height > p2.height;\n ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 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}();\n\nstatic inline bool is_digit(const char c) {\n return (c >= '0') && (c <= '9');\n}\n\nstatic int parse_value(const std::string& s, int& idx) {\... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "int init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str; getline(cin, str);) {\n const int n = str.size();\n int mx = 0;\n int curr = 0, res = 1;\n f... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "int init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str; getline(cin, str);) {\n int mx = 0;\n int curr = 0, res = 1;\n istringstream iss(str); iss.ignore()... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxVal = 0, ans = 0, currentStreak = 0;\n\n for (int num : nums) {\n if (maxVal < num) {\n maxVal = num;\n ans = currentStreak = 0;\n }\n\n if (maxVal =... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int len = 1;\n int mx = *max_element(nums.begin(),nums.end()); \n int tmp_len=0;\n for(int i=0;i<nums.size();i++){ \n if(nums[i]==mx){\n tmp_len++; \n }\n el... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxi = *max_element(nums.begin(), nums.end());\n int ans = 0, cnt = 0, n = nums.size();\n\n for (int i = 0; i < n; i++) {\n if (nums[i] == maxi) {\n cnt++;\n } else\n ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxVal = 0;\n int ans = 0;\n int count = 0;\n \n for(int num:nums)\n {\n if(maxVal < num)\n {\n maxVal = num;\n\n ans = 0;\n ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxValue=0;\n int streak=0;\n int result=0;\n\n for(int num : nums){\n if(num>maxValue){\n result=0;\n streak=0;\n maxValue=num;\n }\n... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int max_val = nums[0];\n int max_len = 1;\n int current_len = 1;\n\n for (int i = 1; i < nums.size(); ++i) {\n if (nums[i] > max_val) {\n max_val = nums[i];\n max_l... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int n=nums.size();\n int m=max_element(nums.begin(), nums.end())-nums.begin(); //Find index of max element\n int maxLen=0, x = nums[m];\n\n // Traverse from nums[m] on\n for (int i = m; i < n; i++) ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int n=nums.size();\n int maxi = *max_element(nums.begin(),nums.end());\n int maxCount=0;\n int count=0;\n for(int i=0;i<n;i++){\n if(nums[i]==maxi){\n count++;\n ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 0 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int ans=1,maxi=nums[0],n=nums.size();\n int c=1,ub=0;\n for(int i=1;i<n;i++)\n {\n if(nums[i]==nums[i-1])\n {\n c++;\n if(nums[i]>=maxi)\n ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 2 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n const int maxElement{ *std::ranges::max_element(nums) };\n int maxSubarray{ 1 };\n\n for (int i{ 1 }, count{ 1 }; i < nums.size(); ++i) {\n if (nums[i - 1] == nums[i] &&\n nums[i] == max... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 2 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n const int maxElement{ *std::ranges::max_element(nums) };\n int maxSubarray{ 1 };\n\n for (int i{ 1 }, count{ 1 }; i < nums.size(); ++i) {\n if (nums[i - 1] == nums[i] &&\n nums[i] == max... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxval = -1;\n // <end pos, range size>\n unordered_map<int, int> maxrange;\n for (auto n : nums)\n maxval = max(maxval, n);\n int currsize = 0;\n for (int i = 0; i < nums.size... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int max_val = *max_element(nums.begin(), nums.end()); \n int max_len = 0, current_len = 0;\n\n for (int num : nums) {\n if (num == max_val) {\n current_len++;\n max_len = ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "class Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int l=nums[0],idx=0;\n for(int i=1;i<nums.size();i++){\n if(nums[i]>l){\n l=nums[i];\n idx=i;\n }\n }\n vector<int> count;\n for(int i=idx;... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "static auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n int longestSubarray(vector<int>& nums) {\n int maxnum = 0;\n for(int num: nums) {\n maxnum = max(num, maxnum);\n ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "class Solution {\npublic:\n static int longestSubarray(vector<int>& nums) {\n const int n=nums.size();\n int m=max_element(nums.begin(), nums.end())-nums.begin(); //Find index of max element\n int maxLen=0, x = nums[m];\n\n // Traverse from nums[m] on\n for (int i = m;... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "class Solution {\n\npublic:\n\n static int longestSubarray(vector<int>& nums) {\n\n const int n=nums.size();\n\n int m=max_element(nums.begin(), nums.end())-nums.begin(); //Find index of max element\n\n int maxLen=0, x = nums[m];\n\n // Traverse from nums[m] on\n\n for... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "#define NO_SAN __attribute__((no_sanitize(\"undefined\", \"address\", \"coverage\", \"thread\")))\n#define INL __attribute__((always_inline))\n\nclass Solution {\npublic:\n static int longestSubarray(const vector<int> &nums) INL NO_SAN {\n uint maxv = 0, l = 0, maxl = 0;\n for (const uint ... |
2,503 | <p>You are given an integer array <code>nums</code> of size <code>n</code>.</p>
<p>Consider a <strong>non-empty</strong> subarray from <code>nums</code> that has the <strong>maximum</strong> possible <strong>bitwise AND</strong>.</p>
<ul>
<li>In other words, let <code>k</code> be the maximum value of the bitwise AND... | 3 | {
"code": "class Solution {\n public:\n Solution() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n }\n\n int longestSubarray(std::vector<int>& nums) {\n int ans = 1;\n const auto highest =\n std::max_element(nums.begin(), nums.end()) - nums.begin();... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\r\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\r\n\r\nstatic const bool Booster = [](){\r\n std::ios_base::sync_with_stdio(false);\r\n std::cin.tie(nullptr);\r\n std::cout.tie(nullptr);\r\n return true;\r\n}();\r\n\r\nvoid parse_input_and_solve(s... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\r\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\r\n\r\nstatic const bool Booster = [](){\r\n std::ios_base::sync_with_stdio(false);\r\n std::cin.tie(nullptr);\r\n std::cout.tie(nullptr);\r\n return true;\r\n}();\r\n\r\nvoid parse_input_and_solve(s... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 0 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nstatic const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return true;\n}();\n\nvoid parse_input_and_solve(std::ofstream& out, s... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n vector<int>nums3;\n for(int i=0;i<nums1.size();i++){\n for(int j=0;j<nums2.size();j++){\n if(nums1[i]==nums2[j])... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n int i=0,j=0;\n sort(nums1.begin(),nums1.end());\n sort(nums2.begin(),nums2.end());\n vector<int> output;\n while(i<nums1.size() && j<nums2.size())\n {\n if (... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n sort(begin(nums1), end(nums1));\n sort(begin(nums2), end(nums2));\n\n vector<int> ans;\n int n1=nums1.size(), n2=nums2.size();\n for(int i=0, j=0; i<n1 && j<n2;){\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 1 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n int i=0,j=0;\n vector<int>arr;\n sort(nums1.begin(),nums1.end());\n sort(nums2.begin(),nums2.end());\n while(i<n&&j<m... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 1 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n int i=0,j=0;\n vector<int>arr;\n sort(nums1.begin(),nums1.end());\n sort(nums2.begin(),nums2.end());\n while(i<n&&j<m... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 1 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2)\n {\n int i = 0, j = 0, n = nums1.size(), m = nums2.size();\n vector<int> a;\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n while(i < n && j < m)\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 1 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int> intersectionArray;\n\n int i = 0;\n int j = 0;\n\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n\n while (i < nums1.size() && j < ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n sort(nums1.begin(),nums1.end());\n sort(nums2.begin(),nums2.end());\n int i=0;\n int j=0;\n vector<int> result;\n while(i<nums1.size()&&j<nums2.size())\n {\... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n // unordered_map<int, int> count;\n // vector<int> ans;\n\n // for (int num : nums1) \n // count[num]++;\n\n // for (int num : nums2) \n // {\n // if (count[num] > 0) \n // {... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int> ans;\n multiset<int> st(nums1.begin(),nums1.end()) ;\n \n for(int i=0;i<nums2.size();i++){\n auto iter = st.find(nums2[i]);\n if( iter !=st.end()){\... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n int a[1001] = {0};\n for(int i = 0; i < nums1.size(); i++){\n a[nums1[i]]++;\n }\n vector<int> v;\n for(int i = 0;i < nums2.size();i++){\n if(a[nums2[i]... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int> binarynum1 (1001, 0); \n vector<int> binarynum2 (1001,0) ; \n vector <int> result ; \n for (int i = 0 ; i<nums1.size() ; i++) {\n binarynum1[nums1[i]] ++; \n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int> paint1(1001);\n vector<int> paint2(1001);\n vector<int> res;\n \n for (int i = 0; i < nums1.size(); ++i) {\n paint1[nums1[i]]++;\n }\n \n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "#include <vector>\n#include <map>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n map<int, int> mp;\n vector<int> result;\n \n // Count frequencies of elements in nums1\n for (int i = 0; i < nums1.s... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n map<int, int> mp;\n vector<int> ans;\n for(int num: nums1){\n if(mp.find(num) == mp.end())\n mp[num]=0;\n mp[num]++;\n }\n\n for(int num: ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n if (nums1.size() > nums2.size())\n return intersect(nums2, nums1);\n\n vector<int> ans;\n unordered_map<int, int> count;\n\n fo... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n map<int,int>m;\n vector<int>ans;\n for(int i=0;i<nums1.size();i++){\n m[nums1[i]]++;\n }\n for(int i=0;i<nums2.size();i++){\n auto it=m.find(nums2[i]);\n... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int> intersec_arr;\n unordered_map<int, int> mapp;\n for (int n : nums1) {\n mapp[n]++;\n }\n for (int m : nums2) {\n auto it = mapp.find(m);\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int>temp;\n map<int,int>mpp;\n int n=nums1.size();\n int m=nums2.size();\n\n if(n<m){\n for(int i=0;i<m;i++){\n mpp[nums2[i]]++;\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> hashmap;\n vector<int> Res;\n for (int i = 0; i < nums1.size(); i++)\n {\n hashmap[nums1[i]]++;\n }\n for (int i = 0; i < nums2.size... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int,int> m;\n\n for(auto i : nums1){\n m[i]++;\n }\n\n vector<int> ans;\n for(auto i : nums2) {\n if(m.find(i) != m.end()) {\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> countMap;\n vector<int> result;\n \n // Count frequencies of each element in nums1\n for(int num : nums1) {\n countMap[num]++;\n }\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int>mp;\n int i;\n vector<int>sol;\n for(i=0;i<nums1.size();i++)\n mp[nums1[i]]++;\n for(i=0;i<nums2.size();i++)\n if(mp.find(nums2[i])!=m... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n vector<int> temp;\n unordered_map<int,int> mp;\n for (int& num : nums1){\n mp[num]++;\n }\n for (int &num : nums2){\n if(mp.find(num)!= mp.end() && mp[nu... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n unordered_map <int, int > element_freq;\n \n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) \n {\n vector<int> result;\n for(int i =0;i<nums1.size();i++)\n element_freq[nums1[i]]++;\n \n for(int i =0;i<nums2.size(... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> mp;\n unordered_map<int, int> ins;\n\n for (int i = 0; i < nums1.size(); i++) {\n mp[nums1[i]]++;\n }\n\n for (int i = 0; i < nums2.size(); ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n map<int,int> mpp;\n vector<int> ans;\n for(int i :nums1){\n mpp[i]++;\n }\n for(int i:nums2){\n if(mpp[i]>0){\n ans.push_back(i);\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n\n vector<int> big;\n vector<int> small;\n vector<int> res;\n\n if(nums1.size() >nums2.size() ){\n big = nums1;\n small = nums2;\n }else{\n big... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int,int>myMap;\n vector<int>ans;\n\n for(const auto& num : nums2){\n myMap[num]++;\n }\n\n for(const auto& num : nums1){\n if(myMap[num]>0)... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n map<int, int> mp1;\n for(int i=0; i<nums1.size(); i++) {\n if(mp1.count(nums1[i])) mp1[nums1[i]]++;\n else mp1[nums1[i]]=1;\n }\n map<int, int> mp2;\n fo... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> vals;\n for (const auto &it: nums1) ++vals[it];\n vector<int> result;\n result.reserve(max(nums1.size(), nums2.size()));\n for (const auto &it: nums2) ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 3 | {
"code": "#include <vector>\n#include <unordered_map>\n\nclass Solution {\npublic:\n std::vector<int> intersect(std::vector<int>& nums1, std::vector<int>& nums2) {\n std::unordered_map<int, int> countMap;\n std::vector<int> result;\n \n // Count occurrences of each element in nums1\n ... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> mpp;\n vector<int> ans;\n \n for(auto it:nums1){\n mpp[it]++;\n }\n for(int i=0; i<nums2.size(); i++){\n if(mpp[nums2[i]]>... |
350 | <p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int , int> mp;\n vector<int> res;\n \n for(int x : nums1){\n mp[x]++;\n } \n\n for(int x : nums2){\n if(mp[x] != 0){\n ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& satisfaction) {\n sort(satisfaction.begin(),satisfaction.end());\n int n=satisfaction.size();\n int ans=0;\n int i=n-1;\n while(i>=0&&satisfaction[i]>=0)\n i--;\n int k=i+1,mult=1,sum=0;\n ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "#pragma GCC optimize(\"O3\",\"unroll-loops\")\nclass Solution {\npublic:\n int maxSatisfaction(vector<int>& v) {\n sort(v.begin(),v.end());\n int tmp=0,suf=0;\n for(int i=v.size()-1;i>=0;i--){\n suf+=v[i];\n if(suf<0) return tmp;\n tmp+=suf;\n ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& satisfaction) {\n int res = 0, presum = 0;\n sort(satisfaction.begin(), satisfaction.end(), greater<int>()); \n for(int i = 0; i < satisfaction.size(); i++){\n if((satisfaction[i] + presum) > 0){\n ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& satisfaction) {\n sort(satisfaction.begin(),satisfaction.end());\n\n\n int maxSum = 0;\n for(int x=0; x <= satisfaction.size(); x++) {\n\n int sum = 0;\n int l = x;\n for(int i=satisfaction... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "#pragma GCC optimize(\"O3\",\"unroll-loops\")\nclass Solution {\npublic:\n int maxSatisfaction(vector<int>& v) {\n sort(v.begin(),v.end());\n int tmp=0,suf=0,n=v.size();\n for(int i=n-1;i>=0;i--){\n suf+=v[i];\n if(suf<0) return tmp;\n tmp+=suf;\n ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& satisfaction) {\n int n = satisfaction.size();\n int suf[n];\n sort(satisfaction.begin(),satisfaction.end());\n suf[n-1]=satisfaction[n-1];\n for(int i =n-2;i>=0;i--){\n suf[i]=suf[i+1]+satisfactio... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& satisfaction) {\n int n = satisfaction.size();\n sort(satisfaction.begin(),satisfaction.end());\n int suf[n];\n suf[n-1]=satisfaction[n-1];\n for(int i=n-2;i>=0;i--){\n suf[i]=suf[i+1]+satisfaction... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\nint get_score(vector<int>& arr) {\n\tint res = 0;\n\tfor (int i = 0; i < arr.size(); i++)\n\t\tres += arr[i] * (arr.size() - i);\n\n\treturn res;\n}\n\nint maxSatisfaction(vector<int>& satisfaction) {\n\tsort(satisfaction.begin(), satisfaction.end(), [](int a, int b) {return a > ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 0 | {
"code": "class Solution {\npublic:\nint get_score(vector<int>& arr) {\n\tint res = 0;\n\tfor (int i = 0; i < arr.size(); i++)\n\t\tres += arr[i] * (arr.size() - i);\n\n\treturn res;\n}\n\nint maxSatisfaction(vector<int>& satisfaction) {\n\tsort(satisfaction.begin(), satisfaction.end(), [](int a, int b) {return a > ... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 1 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& s) {\n sort(s.begin(),s.end());\n int n = s.size();\n vector<int> next(n+2,INT_MIN);\n vector<int> curr(n+2,INT_MIN);\n for (int i=0; i<=n+1; i++) {\n next[i] = 0;\n }\n for (int i=n-... |
1,503 | <p>A chef has collected data on the <code>satisfaction</code> level of his <code>n</code> dishes. Chef can cook any dish in 1 unit of time.</p>
<p><strong>Like-time coefficient</strong> of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its satisfaction level i.e. <code>ti... | 1 | {
"code": "class Solution {\npublic:\n int maxSatisfaction(vector<int>& satisfaction)\n {\n vector<int>v=satisfaction;\n sort(v.begin(),v.end());\n reverse(v.begin(),v.end());\n int sum=0,ans=0;\n for(int i=0;i<v.size();i++){\n if(sum+v[i]>0){\n ans+=... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.