id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,286 | <p>Given an integer array <code>nums</code> and an integer <code>k</code>, return the maximum sum of a <strong>non-empty</strong> subsequence of that array such that for every two <strong>consecutive</strong> integers in the subsequence, <code>nums[i]</code> and <code>nums[j]</code>, where <code>i < j</code>, the co... | 3 | {
"code": "class Solution {\npublic:\n int constrainedSubsetSum(vector<int>& nums, int k) \n {\n int n = nums.size();\n\n multiset<int> s;\n\n vector<int> dp(n+1,0);\n dp[0]=nums[0];\n s.insert(dp[0]);\n int ans=dp[0];\n\n for(int i=1; i<n; i++)\n {\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[301][301];\n int solve(vector<int>& nums,int i,int j){\n if(i>j){\n return 0;\n }\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n\n int maxi=0;\n for(int ind=i;ind<=j;ind++){\n int cost=nums[i-1... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[301][301];\n int solve(int s,int e,vector<int> &nums){\n int n = nums.size();\n if(s>e) return 0;\n if(dp[s][e]!=-1) return dp[s][e];\n int left = (s>0) ? nums[s-1] : 1;\n int right = (e<n-1)? nums[e+1]: 1;\n int ans =0;\n... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[305][305];\n int maxCoins(vector<int>& nums) {\n nums.push_back(1);\n nums.insert(nums.begin(), 1);\n int n = nums.size();\n memset(dp, -1, sizeof(dp));\n return dfs(1, n-2, nums);\n }\n\n int dfs(int l, int r, vector<int>& n... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[301][301];\n int a[301];\n int n;\n\n int rec(int l, int r){\n int prev=1,next=1;\n if(l>r)return 0;\n if(l!=0)prev = a[l-1];\n else prev = 1;\n if(r!=n-1)next = a[r+1];\n else next = 1;\n //cout<<\"prev: \"<<pr... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "\nclass Solution {\npublic:\nint dp[301][301];\nint solve(vector<int> &nums , int i , int j)\n{\n if(i>j) return 0;\n int ans = 0;\n if(dp[i][j]!=-1) return dp[i][j];\n for(int k = i ; k<=j ; k++)\n {\n ans = max(ans , nums[k]*(i-1>=0?nums[i-1] : 1)*(j+1<=nums.size()-1 ? nums[j+1]:1) ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int memo[305][305];\n int solve(vector<int>&nums,int i,int j){\n if(memo[i][j]!=-1){\n return memo[i][j];\n }\n int n = nums.size();\n if(i>j){\n return 0;\n }\n int ans = INT_MIN;\n for(int k=i;k<=j;k+... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[301][301];\n int func(int i,int j,vector<int> &v){\n if(i>j) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int maxi=INT_MIN;\n for(int k=i;k<=j;k++){\n int ans=func(i,k-1,v)+func(k+1,j,v)+v[i-1]*v[k]*v[j+1];\n maxi... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[305][305];\n int maxCoins(vector<int>& nums) {\n nums.push_back(1);\n nums.insert(nums.begin(), 1);\n int n = nums.size();\n memset(dp, -1, sizeof(dp));\n return dfs(1, n-2, nums);\n }\n\n int dfs(int l, int r, vector<int>& n... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[305][305];\n int solve(vector<int> &arr,int i,int j){\n long long temp=0;\n if(i>j)return 0;\n // if(i==j)return arr[i];\n if(dp[i][j]!=-1)return dp[i][j];\n for(int k=i;k<=j;k++){\n long long res=arr[i-1]*arr[k]*arr[j+1... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\n int dp[302][302];\n int func(vector<int>&num,int l,int r){\n if(l>r)\n return 0;\n int maxpts=INT_MIN;\n if(dp[l][r]!=-1)\n return dp[l][r];\n for(int i=l;i<=r;i++){\n int pts=num[l-1]*num[i]*num[r+1];\n pts+=func(num,... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\nstatic inline int64_t maxi(int64_t a, int64_t b) {\n return a < b ? b : a;\n}\n\nstatic inline int64_t maxRemoveCounterIntervals(vector<int>& x, int32_t i, int32_t j, int32_t ii, int32_t jj) {\n if(ii == jj) {\n return x[i] * x[j] * x[ii];\n }\n if(ii != i && jj != j) {\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n \n //MCM +memo taking every kth balloon bursting in the last;\n \n \n int memo[501][501];\n int solve(vector<int> &nums,int i ,int j){\n if(i>j)return 0;\n if(memo[i][j]!=-1)return memo[i][j];\n \n int max_score=INT_MIN;\n for(int k=i;k<=j;k++){\n int c... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int maxCoins(vector<int>& nums) {\n memset(t, -1, sizeof(t));\n\t\tvector<int> arr = {1};\n for(int x: nums) \n\t\t\tarr.push_back(x);\n arr.push_back(1);\n n = arr.size();\n return solve(arr, 1, arr.size() - 2);\n }\n int n;\n int ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n \n //MCM +memo taking every kth balloon bursting in the last;\n \n \n int memo[501][501];\n int solve(vector<int> &nums,int i ,int j){\n if(i>j)return 0;\n if(memo[i][j]!=-1)return memo[i][j];\n \n int max_score=INT_MIN;\n for(int k=i;k<=j;k++){\n int c... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int dp[501][501];\n int n;\n int solve(int i, int j,vector<int>&temp){\n //base condition\n if(i>j) return 0;\n if(i==j){\n int ans = temp[i];\n if(i>0) ans*=temp[i-1];\n if(i<n-1) ans*=temp[i+1];\n return... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\n int dp[501][501];\n int solve(int i,int j,vector<int>& nums){\n if(i>j)return 0;\n\n if(dp[i][j]!=-1)return dp[i][j];\n \n int ans=0; \n for(int k=i;k<=j;k++){\n ans=max(ans,nums[i-1]*nums[k]*nums[j+1]+solve(i,k-1,nums)+solve(k+1,j,num... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int t[501][501];\n int solve(vector<int>& arr , int i , int j){\n if(i>=j)\n return 0;\n if(t[i][j]!=-1)\n return t[i][j];\n int mn=INT_MIN;\n for (int k=i;k<=j-1;k++){\n int temp=solve(arr,i,k)+solve(arr,k+1,j)+(arr[... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n\n int maxCoins(vector<int>& nums) {\n ios::sync_with_stdio(false) ;\n cin.tie(0) ;\n vector<vector<int>> max_coins ;\n // nu folosesc doar juma de matrice, deci cand vreau\n //mat[i][j] , trebuie sa face mat[i][j-i]\n max_coins = vect... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n\n int maxCoins(vector<int>& nums) {\n ios::sync_with_stdio(false) ;\n cin.tie(0) ;\n vector<vector<int>> max_coins ;\n // nu folosesc doar juma de matrice, deci cand vreau\n //mat[i][j] , trebuie sa face mat[i][j-i]\n max_coins = vect... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n\n long int dp[301][301] = {-1};\n\n // returns left over element to be used for recursion purpose.\n long int calc(vector<int>& nums, int i, int j, int left, int right )\n {\n\n if( i > j) return 0;\n if( dp[i][j] != -1 )\n {\n return ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n // Main idea is to start from last removed element\n // It allows us reuse left and right parts in a recursive way\n // For example, if we have the folliwng ballons [2,3,4,5] - if we remore 2,3 last in any order,\n // the first 3[4,5]1 always produce the same resu... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n\n //O(N*2^N)\n int maxCoinsHelper(const vector<int> &nums, map<vector<int>, int> &dpMemo)\n {\n if(dpMemo.find(nums) != dpMemo.end())\n return dpMemo[nums];\n\n int numsCount = nums.size();\n int maxVal = 0;\n vector<int> numsTrunc... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int maxCoins(vector<int>& nums) {\n int n= nums.size()+2;\n vector<int>v(n,1);\n vector<vector<int>>dp(n,vector<int>(n,0));\n int i=1;\n for(auto j: nums) v[i++]=j;\n for(int l=2;l<=n;l++){\n for(int i=0;i<= n-l;i++){\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int maxCoins(vector<int>& nums) {\n nums.insert(nums.begin(), 1);\n nums.push_back(1);\n\n int n = nums.size();\n vector<vector<int>> dp(n, vector<int>(n, 0));\n\n // 0, n\n int ret = 0;\n for (int l = 3; l <= n; l++)\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\nprivate:\nint f(int i,int j,vector<int>v,vector<vector<int>>&dp){\n if(i>j) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int mini=INT_MIN;\n for(int k=i;k<=j;k++){\n int coins=(v[i-1]*v[k]*v[j+1])+f(i,k-1,v,dp)+f(k+1,j,v,dp);\n mini=max(mini,coins);\n }\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 0 | {
"code": "class Solution {\npublic:\n int f(int i , int j , vector<int>& nums , vector<vector<int>> &dp){\n if(i>j) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int maxi = -1;\n for(int k = i ; k<=j ; k++){\n\n int coins = nums[i-1] * nums[k] * nums[j+1] + f(i,k-1,nums,dp) + ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 1 | {
"code": "class Solution {\npublic:\n/*\n\n[1,3,1,5,8,1]\nl = 1 , r = 4\nk = 1, 1 is the last balloon to burst\ntemp = 3 * 1 * 1 + fun(1, 0) + fun(2, 4)\n\nk = 2\ntemp = 1 * 1 * 1 + fun(1, 1) + fun(3, 4)\n\nk = 4\ntemp = 8 * 1 * 1 + fun(1, 3) + fun(5, 4)\n\n[1,3,1,5,8,1]\nl = 1 , r = 3\nk = 1\ntemp = 3 * 1 * 8 + fu... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 1 | {
"code": "class Solution {\n int helper(vector<int>&nums,int left,int right)\n {\n if(right-left==1)return 0;\n \n int maxAmount=INT_MIN;\n for(int i=left+1;i<right;i++)\n {\n int amount=helper(nums,i,right)+helper(nums,left,i)+nums[i]*nums[left]*nums[right];\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 2 | {
"code": "class Solution {\n int helper(vector<vector<int>> &dp, vector<int> &tmp, int s, int e)\n {\n if(dp[s][e] != -1)\n return dp[s][e];\n int ans = 0;\n for(int i = s + 1; i < e; i++)\n {\n ans = max(ans, (tmp[s] * tmp[i] * tmp[e])\n ... |
312 | <p>You are given <code>n</code> balloons, indexed from <code>0</code> to <code>n - 1</code>. Each balloon is painted with a number on it represented by an array <code>nums</code>. You are asked to burst all the balloons.</p>
<p>If you burst the <code>i<sup>th</sup></code> balloon, you will get <code>nums[i - 1] * nums... | 2 | {
"code": "class Solution {\npublic:\n int solve(vector<int>& nums, int left, int right, vector<vector<int>>& dp) {\n if (left > right) {\n return 0;\n }\n\n if (dp[left][right] != -1) {\n return dp[left][right];\n }\n\n int result = 0;\n for (int i =... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "inline constexpr int MAX_M = 1e4 + 5, MIN_M = -1e4 - 5, HIGH = MAX_M - MIN_M, MAX_N = 1e5 + 5;\ninline constinit int fenwick[HIGH + 1]{}, saved[MAX_N]{}, saved_pos = 0;\n\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n vector<int> ans = std::move(nums);\n for (... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "inline constexpr int MAX_M = 1e4, MIN_M = -1e4, HIGH = MAX_M - MIN_M, MAX_N = 1e5;\ninline constinit int fenwick[HIGH + 1]{}, saved[MAX_N]{}, saved_pos = 0;\n\nclass Solution {\npublic:\n Solution() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }\n vector<int> countSmaller(vector<int>& num... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& arr) {\n vector<int>temp = arr;\n sort(temp.begin(),temp.end());\n vector<int>ans(arr.size());\n for(int i =0;i<arr.size();i++){\n int ind = lower_bound(temp.begin(),temp.end(),arr[i])-temp.begin();\... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(std::span<const int> nums) {\n std::vector<int> res;\n res.resize(nums.size());\n std::vector<int> temp_nums;\n temp_nums.resize(nums.size());\n countSmallerImpl(nums, res, temp_nums);\n return res;\n }\n\n... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> sortedNums; \n vector<int> ans(n, 0);\n \n for (int i = n - 1; i >= 0; i--) {\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> smallerToRight(n, 0);\n\n vector<int> sortedEle;\n\n for(int i = n - 1; i >= 0; i--) {\n int curEle = nums[i];\n\n auto it = lower_bound(sorted... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 0 | {
"code": "class Solution {\npublic:\n\n vector<pair<int, int>> temp;\n vector<int> cnt;\n\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n cnt.resize(n);\n temp.resize(n);\n vector<pair<int, int>> arr(n);\n\n for (int i = 0; i < n; i ++){\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\n\n\n void mergeSort(vector<vector<int>> &ans, int lo, int hi) {\n int mid = (lo + hi) / 2;\n if ( lo == mid ) return;\n if ( lo < hi ) {\n int j = mid;\n mergeSort(ans, lo, mid);\n mergeSort(ans, mid, hi);\n for ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\n\n class orderedSet{\n public:\n struct Node{\n int count; // number of elements in this node[Left, Right]\n Node* left, *right;\n Node(){\n count = 0;\n left = nullptr, right = nullptr;\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "#define ll long long\n#define MAX_VAL 20001 // [-10^4, 10^4] shifted by +10^4 to handle negatives\n\nclass SegmentTree {\npublic:\n ll size;\n vector<ll> segmentTree;\n\n // Build the tree with all 0 initially\n SegmentTree(ll size) {\n this->size = size;\n segmentTree = vector<ll... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class SegmentTree{\nprivate:\n vector<long long int> seg;\n int n;\n void update(int pos, int value, long long int idx, int start, int end){\n if(start==end){\n seg[idx]+=value;\n return;\n }\n int midd=(start+end)/2;\n if(pos<=midd) update(pos,val... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\ntypedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;\n\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& num... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "// // approach 1 : using N*N approach , it will give tle \n\n// class Solution {\n// public:\n// vector<int> countSmaller(vector<int>& nums) {\n \n// vector<int> ans;\n\n// for(int i = 0 ; i + 1 < nums.size() ; i++){\n\n// int count = 0;\n\n// for(int j = ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\nint n =200005;\nvector<int>tree;\n\n int sum(int ind){\n int res=0;\n\n while(ind>=1){\n res+=tree[ind];\n ind-=(ind&-ind);\n }\n return res;\n }\n\n void add(int i,int x){\n for(int k=i;k<=n;k+... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\n vector<int> tree;\n int n = 200001;\n int query(int i) {\n int res = 0;\n for (; i > 0; i -= (i & (-i)))\n res += tree[i];\n return res;\n }\n void add(int i, int val) {\n for (; i <= n; i += (i & (-i)))\n tree[i] += val;\n... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\n vector<int>segtree;\n void update(int node,int start,int end,int pos,int val){\n if(pos>end||pos<start)return;\n if(start==end && start==pos){\n segtree[node]+=val;\n return;\n }\n int mid=(start+end)/2;\n update(2*n... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\nprivate:\n int n;\n unordered_map<int,int> segt;\n void update(int index, int val) {\n int l = 0, r = n-1, i = 0, m;\n // cout<<\"index = \"<<index<<endl;\n while(l < r) {\n // cout<<\"l = \"<<l<<\", r = \"<<r<<\", i = \"<<i<<endl;\n seg... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\n vector<int> bit;\n \n void update(int id, int val) {\n int n = bit.size();\n \n while (id < n) {\n bit[id] += val;\n id += (id & -id);\n }\n }\n\n int query(int id) {\n int ans = 0;\n \n while ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Seg{\n vector<int>seg;\npublic:\n Seg(int n){\n seg.resize(n*4, 0);\n }\n\n void update(int l, int r, int idx, int pos, int val){\n if(l==r){\n seg[idx] = val;\n return;\n }\n\n int m = (l+r)/2;\n if(pos<=m){\n update(l, ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class SegmentTree{\n vector<int> tree;\n int n;\npublic:\n SegmentTree(int _n){\n n = _n;\n tree.resize(4*n, 0);\n }\n \n int query(int x, int y, int l, int r, int i){\n if(r < x || y < l) return 0;\n if(x <= l && r <= y) return tree[i];\n\n int m = (l+r... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n// Including tree_order_statistics_node_update\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n#define ll long long int \n#define pb push_back\ntemplate<class T> using pbds=tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_st... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "struct SegmentTreeNode {\n int lo;\n int hi;\n int sum;\n SegmentTreeNode* left;\n SegmentTreeNode* right;\n SegmentTreeNode(int lo, int hi, int sum, SegmentTreeNode* left = nullptr,\n SegmentTreeNode* right = nullptr)\n : lo(lo), hi(hi), sum(sum), left(left), right(right) {}\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\n void merge(vector<vector<int>>& nums_copy, vector<vector<int>>& aux, int first, int mid, int last) {\n for (int i = first; i <= last; i++) {\n aux[i] = nums_copy[i];\n }\n\n int inv_count = 0;\n int i = first, j = mid + 1;\n\n for... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "class Solution {\npublic:\n void mergeSort(vector < vector <int> > &cp,vector < vector <int> > &aux, int start, int mid, int end)\n {\n for(int i = start; i <= end; i++)\n {\n aux[i] = cp[i];\n }\n\n int swap = 0;\n\n int i = start;\n int j = mid +... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "#include<bits/stdc++.h>\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\ntemplate <typename T>\nusing ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;\n\nclass Solution {\npublic... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\ntypedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> st;\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n=nums.size();\... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 1 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n#define pii pair<int,int>\n#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& num... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Node{\npublic:\n shared_ptr<Node> left, right;\n int l, r, count; //count stores number of entries to the left\n Node(int l, int r) : l(l), r(r), count(0) {};\n};\nclass Solution {\n shared_ptr<Node> root;\n void add(int k, shared_ptr<Node> cur_node) {\n // cout << k << endl;\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class SegmentTree {\n vector<int> tree;\n\npublic:\n SegmentTree(int n) { tree.resize(4 * n); }\n void updateTree(int idx, int l, int r, int upIdx) {\n if(upIdx<l || upIdx>r) return;\n if (l == r) {\n tree[idx]++;\n return;\n }\n int mid = l + (r -... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Node{\npublic:\n shared_ptr<Node> left, right;\n int l, r, count; //count stores number of entries to the left\n Node(int l, int r) : l(l), r(r), count(0) {};\n};\nclass Solution {\n shared_ptr<Node> root;\n void add(int k, shared_ptr<Node> cur_node) {\n int l = cur_node->l, r = ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \nusing namespace __gnu_pbds;\n#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>\n\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& v) {\n vector<pair<int,int... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n//https://leetcode.com/problems/count-of-smaller-numbers-after-self/solutions/76607/c-o-nlogn-time-o-n-space-mergesort-solution-with-detail-explanation/\nvoid print(vector<int>& v)\n{\nint n=v.size();\nfor (int i=0;i<n;i++)\n cout<<v[i]<<\" \";\ncout<<endl;\n}\n void suppor... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\nprotected:\n void merge_countSmaller(vector<int>& indices, int first, int last, \n vector<int>& results, vector<int>& nums) {\n int count = last - first;\n if (count > 1) {\n int step = count / 2;\n int mid = first + step;\... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n // vector<int> countSmaller(vector<int>& nums) {\n // if (nums.size() == 1)\n // return {0};\n\n // int n = nums.size();\n // vector<int> ans;\n\n // brute force\n // for (int i = 0; i < n; i++) {\n // int count=0;\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n \n struct seg_tree {\n \n vector<int> tree;\n seg_tree(int n) {\n this->tree = vector<int>(4 * 100002, 0);\n }\n \n void update(int index, int left, int right, int l, int r) {\n \n if (l > r) return... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "#include <bits/stdtr1c++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace std;\nusing namespace __gnu_pbds;\n\nstruct Treap{\n int len;\n const int ADD = 1000010;\n const int MAXVAL = 1000000010;\n unordered_map <long long, int> mp; // Change t... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n void update(vector<int> &t, int v, int tl, int tr, int pos){\n if(tl==tr)\n {\n t[v]++;\n return;\n }\n int tm = (tl + tr)/2;\n if(pos<=tm)\n update(t, 2*v, tl, tm, pos);\n else\n update(t, ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n\n int build(vector<int> &sg, int nd,int l,int r,int mark){\n\n if(l>r){\n return 0;\n }\n\n if(mark<l||mark>r){\n return sg[nd];\n }\n\n if(l==r&&l==mark){\n sg[nd]++;\n return sg[nd];\n }\n... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans(n);\n \n array<int, 3> v[n];\n for(int i=0; i<n; ++i)\n v[i] = {nums[i], ans[i], i};\n mergeSort(0, n - 1, v);\n \n for(in... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> ans(n);\n \n array<int, 3> v[n];\n for(int i=0; i<n; ++i)\n v[i] = {nums[i], ans[i], i};\n mergeSort(0, n - 1, v);\n \n for(in... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n void merge(vector<vector<int>>& nums, int start, int mid, int end, vector<vector<int>>& aux) {\n for(int i = start; i <= end; i++) {\n aux[i] = nums[i];\n }\n\n int inversion_count_per_element = 0;\n int index1 = start, index2 = mid + 1;... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n void merge(vector<vector<int>>& nums, int start, int mid, int end, vector<vector<int>>& aux) {\n for(int i = start; i <= end; i++) {\n aux[i] = nums[i];\n }\n\n int inversion_count_per_element = 0;\n int index1 = start, index2 = mid + 1;... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n void merge(vector<int>& ans, vector<pair<int,int>>& numsPair, int lo, int mid, int hi){\n vector<pair<int, int>> temp(hi-lo+1);\n int i = lo, j = mid+1, k = 0;\n while(i<=mid and j<=hi){\n if(numsPair[i].first <= numsPair[j].first) temp[k++] = numsPair[j++];\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 2 | {
"code": "class Solution {\npublic:\n\n void merge(int left, int mid, int right, vector<pair<int, int>>& arr,vector<int>& count)\n {\n vector<pair<int, int>> temp(right - left + 1);\n \n int i = left;\n int j = mid + 1;\n int k = 0;\n \n while(i <= mid && j <= r... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n vector<int>ans;\n void merge(vector<pair<int,int>>&arr,int s,int mid,int e){\n vector<pair<int,int>>temp(e-s+1);\n int i=s,j=mid+1,idx=0;\n while(i<=mid && j<=e){\n if(arr[i].first >arr[j].first){\n temp[idx++]=arr[j];\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\nprivate:\n map<int,int> mp;\n vector<int> dp;\npublic:\n void mr(int l, int m, int r, vector<pair<int,int>> &a){\n vector<pair<int,int>> n(r-l+1);\n int idx = 0;\n int i = l;\n int j = m+1;\n\n //the left ptr\n int cnt=0;\n while(i... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\n void merge(int l,int mid,int h,vector<int> &nums,vector<int> &cnt,vector<int> &index)\n {\n int n = mid-l+1;\n int m = h-mid;\n\n vector<int> left(n);\n vector<int> right(m);\n // cout << \"left : \";\n for(int i=0;i<n;i++)\n {\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\n void merge(int l,int mid,int h,vector<int> &nums,vector<int> &cnt,vector<int> &index)\n {\n int n = mid-l+1;\n int m = h-mid;\n\n vector<int> left(n);\n vector<int> right(m);\n // cout << \"left : \";\n for(int i=0;i<n;i++)\n {\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "#include <vector>\n#include <algorithm>\n\nclass Solution {\npublic:\n struct Element {\n int value;\n int index;\n int count; // Count of smaller elements to the right\n };\n\n void mergeCount(std::vector<Element>& elements, int left, int mid, int right) {\n int n = ri... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "struct NumSlot {\n int num;\n int index;\n int count;\n};\n\nclass Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n vector<NumSlot> arr(nums.size());\n for (int i = 0; i < nums.size(); i++) {\n arr[i].num = nums[i];\n arr[i].index = i;\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n struct CountSmaller {\n int value;\n int pos;\n int count = 0;\n };\n\n using iterator = std::vector<CountSmaller>::iterator;\n\n void merge(iterator left1, iterator right1, iterator left2, iterator right2, iterator dest) {\n iterator begi... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "static const int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n struct CountSmaller {\n int value;\n int pos;\n int count = 0;\n };\n\n using iterator = std::vector<CountSmaller>::iterator;\n\n void merge(iterator left1, itera... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n vector<int> result(nums.size());\n vector<int> indexes(nums.size());\n iota(begin(indexes), end(indexes), 0);\n sort(result, nums, indexes, 0, nums.size() - 1);\n return result;\n }\n\n v... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\n\npublic:\n\n vector<vector<int>>seg; \n\n \n\n vector<int> combine(vector<int>& a , vector<int>& b )\n\n {\n\n int n = a.size() ; \n\n int m = b.size() ; \n\n \n\n vector<int>ans(n+m) ;\n\n \n\n int l =0 , r= 0 , index= 0; \n\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n void mergesort(vector<int>& arr, int l, int r, vector<int>& counts, vector<int>& indices) {\n if (r <= l) {\n return;\n }\n int mid = (l + r) / 2;\n mergesort(arr, l, mid, counts, indices);\n mergesort(arr, mid + 1, r, counts, ind... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n vector<int> countSmaller(vector<int>& nums) {\n int n = nums.size();\n vector<int> res(n, 0);\n vector<pair<int, int>> indexedNums(n);\n\n for (int i = 0; i < n; ++i) {\n indexedNums[i] = {nums[i], i};\n }\n\n mergesort(ind... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "// #include <ext/pb_ds/assoc_container.hpp>\n// // #include <ext/pb_ds/tree_policy.hpp>\n// using namespace __gnu_pbds;\n// template<class T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;\n\n// class Solution {\n// public:\n// vector<int> countSmaller(v... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "void merge(vector<pair<int,int>>&num , int low ,int mid , int high , vector<int>&result)\n{\n int n1 = mid - low + 1;\n int n2 = high - mid;\n vector<pair<int,int>>L(n1);\n vector<pair<int,int>>R(n2);\n for(int i = 0; i < n1 ; i++)\n {\n L[i] = num[i + low];\n }\n for(int i =... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\nprivate:\n void merge(vector<pair<int, int>>& arr, int start, int end, vector<int>& ans) {\n int mid = start + (end - start) / 2;\n int len1 = mid - start + 1;\n int len2 = end - mid;\n \n vector<pair<int, int>> left(arr.begin() + start, arr.begin() +... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n void merge(int left, int mid, int right, vector<pair<int, int>>& v, vector<int>& cnt) {\n int ls = mid - left + 1;\n int rs = right - mid;\n vector<pair<int, int>> lef(ls);\n vector<pair<int, int>> rig(rs);\n\n for (int i = 0; i < ls; i++) {... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n void merge(vector<int>& nums,vector<int>& cnt,vector<pair<int,int>>& tempo,int s,int e,int mid){\n int len1=mid-s+1;\n int len2=e-mid;\n vector<pair<int,int>> temp1(len1);\n vector<pair<int,int>> temp2(len2);\n for(int i=0;i<len1;i++){\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n void merge(vector<int>& nums,vector<int>& cnt,vector<pair<int,int>>& tempo,int s,int e,int mid){\n int len1=mid-s+1;\n int len2=e-mid;\n vector<pair<int,int>> temp1(len1);\n vector<pair<int,int>> temp2(len2);\n for(int i=0;i<len1;i++){\n ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n\n vector<pair<int,int>> insert(vector<pair<int,int>> &nums, int i, int j, vector<int> &ans){\n\n if(i==j){\n return vector<pair<int,int>> {{nums[i].first, nums[i].second}};\n }\n\n int mid = (i+j)/2;\n vector<pair<int,int>> a;\n v... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n void func(vector<vector<int>>::iterator l, vector<vector<int>>::iterator r, vector<int>& vec)\n {\n if(r-l<=1)\n return;\n \n vector<vector<int>>::iterator m = l+(r-l)/2;\n func(l,m,vec);\n func(m,r,vec);\n for(vector<ve... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n \n#include <functional> // for less\nusing namespace __gnu_pbds ;\n#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> \nclass Solution {\npublic:\nvector<int>ans ;\nvoid f(vector<vector<int>>&nums , int l , int m ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n\n\n\nvoid add(int index,int low,int high,int update_index,vector<int>&tree){\n if(low==high) {\n tree[index]++;\n return ;\n }\n \n int mid=low+(high-low)/2;\n if (update_index <= mid) {\n add(2 * index + 1, low, mid, update_index, tree);\n... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "#define iterator vector<vector<int>>::iterator\nclass Solution{\n\n void solve(iterator l, iterator r, vector<int>& count){\n if (r - l <= 1) return;\n iterator m = l + (r - l) / 2;\n solve(l , m , count);\n solve(m , r ,count);\n\n for(iterator i = l, j = m; i<m; ... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n // iterator를 vector<vector<int>>::iterator로 정의하여 코드를 간결하게 만듦\n #define iterator vector<vector<int>>::iterator\n\n // 병합 정렬의 원리로 배열을 정렬하면서 오른쪽의 작은 숫자 개수를 계산\n // l: 시작 반복자, r: 끝 반복자, count: 결과를 저장하는 벡터\n void sort_count(iterator l, iterator r, vector<int>& count) {... |
315 | <p>Given an integer array <code>nums</code>, return<em> an integer array </em><code>counts</code><em> where </em><code>counts[i]</code><em> is the number of smaller elements to the right of </em><code>nums[i]</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nu... | 3 | {
"code": "class Solution {\npublic:\n #define iterator vector<vector<int>>::iterator\n void sort_count(iterator l, iterator r, vector<int>& count) {\n if (r - l <= 1) return;\n iterator m = l + (r - l) / 2;\n sort_count(l, m, count);\n sort_count(m, r, count);\n for (iterat... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.