id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n\n // long long ans=0;\n \n stack<int> st;\n int n=nums.size();\n\n vector<int> nextg(n);\n\n for(int i=n-1;i>=0;i--)\n {\n while(!st.empty() and nums[st.top()]<nums[i]... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getNextGorEArray(vector<int>& v) {\n vector<int> res(v.size(),-1);\n stack<int> s;\n for(int i=v.size()-1;i>=0;i--) {\n while(!s.empty() && v[s.top()] < v[i]) {\n s.pop();\n }\n if(s.empty()) res... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n=nums.size();\n vector<int>v(n,0);\n vector<int>v2(n,0);\n map<int,int>h;\n stack<int>s;\n long long ans=0;\n for(int i=n-1;i>=0;i--){\n int a=nums[i];\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n stack<pair<int, int>> stack;\n long long result = 0;\n for (int n : nums) {\n while (!stack.empty() && stack.top().first < n)\n stack.pop();\n if (stack.empty() || sta... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "// 14:31\n\nclass Solution {\nprivate:\n struct Item\n {\n int val;\n int cnt;\n };\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int N = (int)nums.size();\n long long res = N;\n stack<Item> st;\n for (int i = 0; i < N; )\n {\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n long long pow1(int x){\n long long val=(long long )x;\n val=(val*val+val)/2;\n return val;\n }\n long long numberOfSubarrays(vector<int>& k) {\n int n=k.size();\n long long ans=0;\n stack<int>s;\n int a,b;\n for(in... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "// Idea: monotonic stack。\n// we can use monotonic stack to discover the non-trivial special arrays that\n// each has 2+ elements.\n// trivial subarrays are ones with just one element.\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n vector<int> stk; // monotonic st... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& arr) {\n int n = arr.size();\n\n vector<int> same_num(n, 1);\n\n //find prev greater elem\n stack<int> s;\n for(int i=0;i<n;i++){\n while(!s.empty() && arr[s.top()] <= arr[i]){\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 0 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& arr) {\n int n = arr.size();\n\n vector<int> same_num(n, 1);\n\n //find prev greater elem\n stack<int> s;\n for(int i=0;i<n;i++){\n while(!s.empty() && arr[s.top()] <= arr[i]){\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "#define ll long long \nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ll n=nums.size();\n vector<int>a(n,1);\n // for(int i=0;i<n;i++){\n // for(int j=i;j<n;j++){\n // if(nums[i]==nums[j]){\n // a[i]++;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& arr) {\n int n = arr.size();\n long long cnt = 0;\n stack <pair<int, int>> st;\n\n if (n == 1) return 1;\n\n int j = 1;\n st.push({arr[0], 1});\n\n while (j < n){\n\n while (j... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& arr) {\n int n = arr.size();\n\n vector<int> prev_greater(n, -1);\n vector<int> same_num(n, 1);\n\n //find prev greater elem\n stack<int> s;\n for(int i=0;i<n;i++){\n while(!s.empty(... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n vector<int> nextGreater(n, -1);\n stack<int> st;\n for(int i = 0; i < n; i++) {\n while(!st.empty() && nums[st.top()] < nums[i]) \n st.pop();\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "using ll=long long;\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int l=0,r=0;\n int n=nums.size();\n stack<int> st;\n unordered_map<int,int> mp;\n ll ans=0;\n while(r<n){\n ans++;\n while(st.size() && nums... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n vector<int> stk{};\n auto ans = 0ll;\n unordered_map<int, int> cnt{};\n for(int i = 0 ; i < n; ++i) {\n while(!stk.empty() && stk.back() < nums[i]) {\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& a) {\n long long n, ans;\n n = ans = a.size();\n stack<int> st;\n st.push(a.back());\n map<long long, long long> mp;\n mp[a.back()]++;\n for (int i = n - 2; i >= 0; i--) {\n i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n=nums.size();\n vector <long long> v(n, 0);\n int ind=-1;\n vector <long long> score(n,1);\n for(int i=0;i<nums.size();i++)\n {\n while(ind!=-1 and nums[v[ind]]<nums[i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n vector<int> nge(vector<int> &nums)\n {\n stack<int> st;\n int n = nums.size();\n vector<int> ans(nums.size(), -1);\n for(int i = nums.size()-1; i >= 0; i--)\n {\n if(st.empty()) \n {\n st.push(i);\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n stack<long long> s;\n long long ans=nums.size();\n unordered_map<long long ,long long>m;\n for(int i=0;i<nums.size();i++){\n int ele=nums[i];\n int cnt=0;\n while(!s.empty() and s.... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "#define ll long long \nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& v) {\n stack<ll> s;\n map<ll,ll> m;\n s.push(v[0]);\n m[v[0]]++;\n ll ans=v.size();\n v.push_back(2000000000);\n for(int i=1;i<v.size();i++){\n if(v[i]>... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\n\n vector<pair<int,int>> t;\n long helper(vector<int>& nums, int begin, int end, int t_index) \n {\n if (begin+1==end) return 1;\n if (t_index>=nums.size()) return 0;\n while (t[t_index].second < begin || t[t_index].second >=end) t_index++;\n //if (t_i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "#define ll long long \nconst int M = 1e9 + 7; \n \nclass Solution { \npublic: \n vector<ll> dp; \n\n ll dfs(int u, vector<bool>& vis, vector<int>& nums) { \n vis[u] = 1; \n ll res = 0; \n if(dp[u] != nums.size() && nums[u] == nums[dp[u]]) { \n res = 1 + dfs(dp[u], vis,... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\n\n vector<pair<int,int>> t;\n long helper(vector<int>& nums, int begin, int end, int t_index) \n {\n if (begin+1==end) return 1;\n if (t_index>=nums.size()) return 0;\n while (t[t_index].second < begin || t[t_index].second >=end) t_index++;\n if (t_ind... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int, int> mp;\n stack<int> st;\n long long ans = 0;\n for (int i = 0; i < n; i++) {\n ans += mp[nums[i]]++ + 1;\n while (st.size() ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n long long ans=0;\n stack<int>st;\n map<int,int>mp;\n for(int x : nums){\n while(!st.empty() and st.top()<x){\n mp[st.top()]--;\n st.pop();\n }\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n // stack\n long long ans=1;\n vector<vector<int>>st;\n st.push_back({nums[0],1});\n for(int i=1;i<nums.size();i++){\n while(st.size()>0 && st.back()[0]<nums[i]){\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> stack;\n long long res =0;\n for(auto& a:nums){\n while(!stack.empty()&&stack.back()[0]<a) stack.pop_back();\n if(stack.empty()||sta... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "using ll=long long;\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n stack<int>st;ll ans=0;\n // ll ct=0;\n unordered_map<int,ll>mp;\n for(int i=0;i<nums.size();i++){\n if(st.empty()){\n st.push(nums[i]);\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "#define ll long long \nconst int M = 1e9 + 7; \n \nclass Solution { \npublic: \n vector<ll> dp; \n\n ll dfs(int u, vector<bool>& vis, vector<int>& nums) { \n vis[u] = 1; \n ll res = 0; \n if(dp[u] != nums.size() && nums[u] == nums[dp[u]]) { \n res = 1 + dfs(dp[u], vis,... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "#define ll long long \nconst int M = 1e9 + 7; \n \nclass Solution { \npublic: \n vector<ll> dp; \n\n ll dfs(int u, vector<bool>& vis, vector<int>& nums) { \n vis[u] = 1; \n ll res = 0; \n if(dp[u] != nums.size() && nums[u] == nums[dp[u]]) { \n res = 1 + dfs(dp[u], vis,... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ll res = 0;\n map<int, ll> cnt, lst;\n stack<array<ll, 2>> st;\n\n for (int i = 0; i < nums.size(); i++) {\n ll x = nums[i];\n while (st.size() && x >... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n long long res = 0;\n stack<vector<int>> s;\n for (auto c: nums) {\n while (s.size() && s.top()[0] < c) s.pop();\n if (s.size() == 0 || s.top()[0] > c) s.push({c, 0});\n re... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n long long res = 0;\n stack<vector<int>>s;\n for (auto c: nums) {\n while (s.size() && s.top()[0] < c) s.pop();\n if (s.size() == 0 || s.top()[0] > c) s.push({c, 0});\n res... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n long long res = 0;\n stack<vector<int>>s;\n for (auto c: nums) {\n while (!s.empty() && s.top()[0] < c) s.pop();\n if (s.size() == 0 || s.top()[0] > c) s.push({c, 0});\n r... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n // long long count = 0;\n // for(int i=0; i<nums.size(); i++){\n // for(int j=i; j<nums.size(); j++){\n // if(nums[i] == nums[j]){\n // int maxi = 0;\n // ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "using ll=long long;\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ll ans=0;\n map<ll,ll>mp;\n for(int i=0;i<nums.size();i++)\n {\n mp[nums[i]]++;\n auto it =mp.begin();\n\n while(it->first!=nums[i])\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n long long pow1(int x){\n long long val=(long long )x;\n val=(val*val+val)/2;\n return val;\n }\n long long numberOfSubarrays(vector<int>& k) {\n int n=k.size();\n long long ans=0;\n stack<int>s;\n unordered_map<int,int>f;... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n class stree\n {\n public:\n vector<int> t;\n stree (int n)\n {\n t.resize(4*n);\n }\n void build(int idx, int tl, int tr, vector<int>&nums)\n {\n if(tr==tl)\n {\n t[idx]=nums[tl]; return;\n }\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "using ll = long long;\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n /*\n for i in [0,n-1]:\n for j in [i:n-1]:\n if nums[i]!=nums[j] : continue;\n if nums[j]>nums[i] : break;\n else ans++;\n */... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\nint bs(vector<int>&arr,int i){\n int start=0,end=arr.size()-1;\n while(start<=end){\n int mid=start+(end-start)/2;\n if(arr[mid]==i)return mid;\n else if(arr[mid]<i)start=mid+1;\n else end=mid-1;\n }\n return -1;\n}\nint bss(vector<int>&arr... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\n vector<int> prev_greater(vector<int> arr) {\n int n = arr.size();\n \n vector<int> PGE(n, -1);\n stack<int> stk;\n \n for (int i = n-1; i >= 0; i--) {\n while (!stk.empty() && arr[stk.top()] < arr[i]) {\n PGE[stk.top(... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 1 | {
"code": "class Solution {\npublic:\n void solve2(vector<int>& nums,vector<int> &prevg) {\n int n=nums.size();\n stack<int> st;\n st.push(0);\n prevg[0]=-1;\n for(int i=0;i<n;i++){\n while(!st.empty() && nums[st.top()]<=nums[i]){\n st.pop();\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\n unordered_map<int, vector<int>> indicesMap;\n vector<int> nextGreater;\npublic:\n int query(int ele, int L, int R) {\n int leftIndex = lower_bound(indicesMap[ele].begin(), indicesMap[ele].end(), L) - indicesMap[ele].begin();\n int rightIndex = lower_bound(indicesMa... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ll ans = 0, n = nums.size();\n vector<ll> sub(n, 1), ci(n, -1);\n unordered_map<ll, ll> seen;\n \n stack<int> st;\n for(int i=0; i<n; i++){\n while(!s... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n#define ll long long\n long long numberOfSubarrays(vector<int>& nums) {\n map<ll,vector<ll>>m;\n for(int i=0;i<nums.size();i++){\n m[nums[i]].push_back(i);\n } \n stack<pair<int,int>>s;\n int arr[nums.size()];\n memset(arr... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n \n void build(int node,int st,int en, vector<int> &arr,vector<int> &tree)\n{\n if(st==en)\n {\n tree[node]= arr[st]; return;\n }\n int mid = (st+en)/2;\n\n build(2*node+1,st,mid,arr,tree); //left portion\n build(2*node+2,mid+1,en,arr,tree);\n\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n\n vector<int>NGR(vector<int>input,int n){\n\n vector<int> result(n, n); stack<int> s;\n\n for (int i = 0; i < n; i++) { \n while (!s.empty() && input[s.top()] < input[i]) {\n result[s.top()] = i;\n s.pop();\n }\n s.push(i);\n }\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ios::sync_with_stdio(0); cin.tie(0);\n unordered_map<int, vector<int>> m;\n stack<int> s;\n long long ans = 0;\n vector<int> greater(nums.size(), -1), dp(nums.size(), 1);\n for(int i ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n long long ans = nums.size();\n\n map<int, int> m;\n\n for (auto& x : nums) {\n while (m.size() && m.begin()->first < x) {\n m.erase(m.begin());\n }\n\n if (... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& a) {\n long long ans=0;\n map<int,int> m;\n int n=a.size();\n for(int i=0; i<n; i++){\n int num=a[i];\n for(auto x:m){\n if(x.first<num){\n long long c... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long pow1(int x){\n long long val=(long long )x;\n val=(val*val+val)/2;\n return val;\n }\n long long numberOfSubarrays(vector<int>& k) {\n int n=k.size();\n long long ans=0;\n stack<int>s;\n map<int,int>f;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n map<int, vector<int>> mp;\n for(int i=0;i<n;i++){\n mp[nums[i]].push_back(i);\n }\n // next max \n vector<int> nxt(n,-1);\n stack<int> st;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "using LL=long long;\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n=nums.size();\n stack<int> stk;\n vector<int> prevbigger(n,-1);\n unordered_map<int,vector<int>> m;\n for(int i=n-1;i>=0;i--){\n while(!stk.empty() && nu... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n unordered_map<int,vector<int>> indices;\n int n = nums.size();\n stack<int> sta_ind;\n long long ans = 0;\n for(int i = 0;i < n;i++) {\n indices[nums[i]].push_back(i);\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long find(int id,vector<int>& v){\n long long n=v.size();\n long long i=0,j=v.size()-1,ans=n;\n while(i<=j){\n int mid=(i+j)/2;\n if(v[mid]>=id){\n ans=mid;\n j=mid-1;\n }else{\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ll n = nums.size();\n\n vector<ll> bigger_to_right(n);\n stack<ll> st;\n for (ll i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()] <= nums[i]) st.... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "#include <string>\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <queue>\n#include <set>\n#include <fstream>\n#include <map>\n#include <stack>\n\nusing namespace std;\n\n\n//Definition for a binary tree node.\n// struct TreeNode {\n// int val;\n// TreeNode *left;\n// Tr... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "#include <string>\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <queue>\n#include <set>\n#include <fstream>\n#include <map>\n#include <stack>\n\nusing namespace std;\n\n\n//Definition for a binary tree node.\n// struct TreeNode {\n// int val;\n// TreeNode *left;\n// Tr... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n int query(int ele, int L, int R, unordered_map<int,vector<int>>& indicesMap) {\n // Get the indices of the element ele from the indicesMap\n auto& indices = indicesMap[ele];\n \n // Find the lower bound for L and R\n int leftIndex = lower_bo... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "#define ll long long\n\nll solve(const vector<int>& temp, int index) {\n ll cnt = 0;\n int n = temp.size();\n int i = 0, j = n - 1;\n\n while (i <= j) {\n int mid = (i + j) / 2;\n if (temp[mid] > index) {\n cnt = n - mid;\n j = mid - 1;\n } else {\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n vector<int> largest(n,0);\n stack<int> st;\n st.push(-1);\n\n for(int i=0; i<n; i++) {\n int idx = st.top();\n while(idx != -1 && nums[idx]<=nums... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution\n{\npublic:\n vector<int> nextGreaterElement(vector<int> &arr, int n)\n {\n stack<int> s;\n s.push(-1);\n vector<int> ans(n);\n\n for (int i = n - 1; i >= 0; i--)\n {\n int curr = arr[i];\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n // next greater element \n vector<int> next_greater(n, -1);\n stack<int> st;\n st.push(-1);\n for(int i = n-1; i >= 0; i--){\n while(st.top() != -1){... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size();\n vector<int> left(n, -1);\n\n stack<int> st;\n unordered_map<int, vector<int>> mp;\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\n vector<int> next_greater(vector<int> &nums)\n {\n int n=nums.size();\n vector<int> res(n, n);\n stack<int> s;\n for(int i=0; i<n; i++)\n {\n if(s.empty())\n {\n s.push(i);\n continue;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n int n = nums.size(), maxi = nums[0];\n vector<long long> v(n);\n unordered_map<int, vector<int>> mp;\n stack<int> st;\n st.push(-1);\n for (int i = 0; i < n; i++) {\n int i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "#include <vector>\n#include <unordered_map>\n#include <stack>\n#include <algorithm>\n\nclass Solution {\npublic:\n long long numberOfSubarrays(std::vector<int>& nums) {\n std::unordered_map<int, std::vector<int>> mpp;\n \n // Fill the map with indices of each element\n for (i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(std::vector<int>& nums) {\n std::unordered_map<int, std::vector<int>> mpp;\n \n // Fill the map with indices of each element\n for (int i = 0; i < nums.size(); ++i) {\n mpp[nums[i]].push_back(i);\n }\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "struct Node{\n int mx;\n Node(){\n mx=0;\n }\n};\n\nNode t[4*100000];\n\nNode merge(Node a, Node b){\n Node ans;\n ans.mx=max(a.mx, b.mx);\n return ans;\n}\n\nvoid build(int id, int l, int r, vector<int>& nums){\n if(l==r){\n t[id].mx=nums[l];\n return;\n }\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long find(int in,int range,int val, map<int,vector<int>>&cnt){\n return upper_bound(cnt[val].begin(),cnt[val].end(),in+range-1)-cnt[val].begin()-1;\n }\n long long numberOfSubarrays(vector<int>& nums) {\n int n=nums.size();\n\n vector<long long... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "struct node{\n int mx = -1e9;\n};\nclass Solution {\npublic:\n static const int N = 4*(1e5+1);\n node t[N];\n int a[N];\n node merge(node a,node b){\n node p;\n p.mx = max(a.mx,b.mx);\n return p;\n }\n void build(int idx,int l,int r){\n if(l > r)return;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int> &nums){\n int n = nums.size(); \n vector<int> nge(n, n); \n\n stack<int> st; \n\n for (int i = n - 1; i >= 0; i--){\n while (!st.empty() && nums[st.top()] <= nums[i]) st.pop(); \n\n i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long find(int in,int range,int val, map<int,vector<int>>&cnt){\n return upper_bound(cnt[val].begin(),cnt[val].end(),in+range-1)-cnt[val].begin()-1;\n }\n long long numberOfSubarrays(vector<int>& nums) {\n int n=nums.size();\n\n vector<long long... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int> &nums){\n int n = nums.size(); \n vector<int> nge(n, n); \n\n stack<int> st; \n\n for (int i = n - 1; i >= 0; i--){\n while (!st.empty() && nums[st.top()] <= nums[i]) st.pop(); \n\n i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n unordered_map<int, vector<int>> vec;\n int n = nums.size();\n for(int i=0;i<n;i++)\n vec[nums[i]].push_back(i);\n vector<int> nextgreater(n,INT_MAX);\n vector<pair<int,int>> st;\n... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n \n int getcount(vector<int> v, int pos)\n {\n if(pos >= v.back()) return v.size();\n int ans = 0,l=0,r=v.size()-1,mid,val;\n while(l<=r)\n {\n mid = (l+r)/2;\n val = v[mid];\n if(pos < val) \n r... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\n typedef long long ll;\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n unordered_map<int,vector<int>>mp;\n for(int i=0;i<nums.size();i++) mp[nums[i]].push_back(i);\n int n=nums.size();\n vector<int>next(n,n);\n stack<int>st;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "typedef int ll;\n\nint N;\nvector<ll> segtree;\n\nvoid pull(int t) {\n segtree[t] = max(segtree[2*t], segtree[2*t+1]);\n}\n\nvoid point_set(int idx, ll val, int L = 1, int R = N, int t = 1) {\n if (L == R) segtree[t] = val;\n else {\n int M = (L + R) / 2;\n if (idx <= M) point_set(i... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n \n long long numberOfSubarrays(vector<int>& nums) {\n long long ans = 0;\n map<int, vector<int>> mp;\n for(int i=0; i<nums.size(); i++){\n if(mp.find(nums[i])==mp.end()){\n ans++;\n mp[nums[i]] = {i};\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& v) {\n multiset<int> s;\n long long ans=0;\n map<int,int> m;\n for(int i=0; i<v.size(); i++){\n while(s.size() && *s.begin()<v[i]){\n m[*(s.begin())]--;\n s.erase(s.b... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "using ll = long long;\nusing pll = pair<ll, ll>;\n\nclass Solution {\npublic:\n void compress(vector<int>& arr) {\n ll n = arr.size();\n\n vector<pll> sorted(n);\n for (ll i = 0; i < n; i++) sorted[i] = {arr[i], i};\n sort(sorted.begin(), sorted.end());\n\n for (ll i =... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "using ll = long long;\n\nclass Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n ll n = nums.size();\n\n vector<ll> bigger_to_right(n);\n stack<ll> st;\n for (ll i = n - 1; i >= 0; i--) {\n while (!st.empty() && nums[st.top()] <= nums[i]) st.... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "using ll = long long;\nusing pll = pair<ll, ll>;\n\nclass Solution {\npublic:\n void compress(vector<int>& arr) {\n ll n = arr.size();\n\n vector<pll> sorted(n);\n for (ll i = 0; i < n; i++) sorted[i] = {arr[i], i};\n sort(sorted.begin(), sorted.end());\n\n for (ll i =... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long numberOfSubarrays(vector<int>& nums) {\n map<int,vector<int>> mp;\n int n=nums.size(); \n for(int i=0;i<n;i++){\n mp[nums[i]].push_back(i);\n }\n\n vector<int> prevGr(n,-1);\n stack<int> st;\n for(int i = n... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "using ll = long long;\nusing pll = pair<ll, ll>;\n\nclass Solution {\npublic:\n void compress(vector<int>& arr) {\n ll n = arr.size();\n\n vector<pll> sorted(n);\n for (ll i = 0; i < n; i++) sorted[i] = {arr[i], i};\n sort(sorted.begin(), sorted.end());\n\n for (ll i =... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\n// Define ordered_set using PBDS\n#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>\n\nclass Sol... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n long long Calc(vector<array<int,2>> &vseg,vector<int> &vi)\n {\n long long ans=0;\n int n=vi.size(),i=0;\n vector<array<int,2>> nseg;\n for(auto [le,ri]:vseg)\n {\n int cnt=0;\n for(;i<n && vi[i]<=ri;++i)\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "typedef long long ll;\n\nclass SegmentTree\n{\n\nprivate:\n\n vector<ll> seg;\n\npublic:\n\n SegmentTree(ll n)\n {\n seg.resize(4*n+1);\n }\n\n void build(ll ind,ll lo,ll hi,vector<ll> &a)\n {\n if(lo==hi)\n {\n seg[ind]=a[lo];\n return;\n ... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n #define vi vector<int> \n #define pii pair<int , int>\n #define dbg(x) cout << #x << \" : \" << x << endl\n long long numberOfSubarrays(vector<int>& a) {\n ll ans = 0;\n\n // nice one\n\n // iterate over the numbers in a... |
3,382 | <p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
<p>Return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>, where the <strong>first</strong> and the <strong>last</strong> elements of the subarray are <em>equal</em> to the <strong>largest<... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n #define vi vector<int> \n #define pii pair<int , int>\n #define dbg(x) cout << #x << \" : \" << x << endl\n long long numberOfSubarrays(vector<int>& a) {\n ll ans = 0;\n\n // nice one\n int n = a.size();\n\n map<i... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 0 | {
"code": "class Solution {\npublic:\n string findLatestTime(string s) {\n for(int i=0;i<s.size();i++){\n if(s[i]=='?'){\n if(i==0 && (s[i+1]-48<2 || s[i+1]-48==15))\n s[i]='1';\n else if(i==0)\n s[i]='0';\n else if(i==1 &&... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 0 | {
"code": "class Solution {\npublic:\n string findLatestTime(string time) {\n string result = \"\";\n char leadHour = time[0];\n char subHour = time[1];\n\n char leadMinute = time[3];\n char subMinute = time[4];\n\n if (leadHour == '?') {\n if (subHour == '0' ||... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 0 | {
"code": "class Solution {\npublic:\n string findLatestTime(string s) {\n if(s[0]=='?')\n {\n if(s[1]=='?') s[0]='1';\n else if(s[1]-'0'>1) s[0]='0';\n else s[0]='1';\n }\n if(s[1]=='?')\n {\n if(s[0]=='0') s[1]='9';\n else ... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 0 | {
"code": "\nclass Solution {\npublic:\n\tstring findLatestTime(string& s) {\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s[i] == '?') {\n\t\t\t\tif (i == 0) {\n\t\t\t\t\tif (s[1] == '?' || s[1] - '0' < 2) s[0] = '1';\n\t\t\t\t\telse s[0] = '0';\n\t\t\t\t}\n\t\t\t\telse if (i == 1) s[0] == '1' ? s[1] = '1' ... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 1 | {
"code": "class Solution {\npublic:\n string findLatestTime(string time) {\n // Fix hour\n if (time[0] == '?') {\n if (time[1] == '?' || time[1] <= '1') {\n time[0] = '1'; // If second digit is '?' or between '0' and '1', max is 11:xx\n } else {\n ... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 1 | {
"code": "class Solution {\npublic:\n string findLatestTime(string s) {\n if (s[0] == '?') \n {\n if (s[1] != '0' && s[1] != '1' && s[1] != '?')\n s[0] = '0';\n else \n s[0] = '1';\n }\n if (s[1] == '?') \n {\n if (s... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 3 | {
"code": "class Solution {\npublic:\n string findLatestTime(string s) {\n string ans;\n if(s[0] == '?') {\n s[0] = (s[1] == '?' || s[1] < '2') ? '1' : '0';\n }\n if(s[1] == '?') {\n s[1] = (s[0] == '1') ? '1' : '9';\n }\n if(s[3] == '?') {\n ... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 3 | {
"code": "class Solution {\npublic:\n string findLatestTime(string s) {\n if (s[0] == '?' && (s[1] == '1' || s[1] == '0' || s[1] == '?')) {\n s[0] = '1';\n }\n else if (s[0] == '?') {\n s[0] = '0';\n }\n\n if (s[1] == '?' && s[0] == '0') {\n s[1]... |
3,361 | <p>You are given a string <code>s</code> representing a 12-hour format time where some of the digits (possibly none) are replaced with a <code>"?"</code>.</p>
<p>12-hour times are formatted as <code>"HH:MM"</code>, where <code>HH</code> is between <code>00</code> and <code>11</code>, and <code>MM</... | 3 | {
"code": "\n\n #include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string findLatestTime(string timeString) {\n int a=8678,b=8678,c=846;\n // If hours tens and ones places are both '?', set them to '11'\n if (timeString[0] == '?' && timeString[1] == '?') {\n time... |
3,373 | <p>You are given an integer array <code>nums</code>.</p>
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div cl... | 0 | {
"code": "class Solution {\npublic:\n \n bool isPrime(int n){\n if (n <= 1)\n return false;\n for (int i = 2; i <= n / 2; i++)\n if (n % i == 0)\n return false;\n\n return true;\n }\n int maximumPrimeDifference(vector<int>& nums) {\n int fr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.