id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
0
{ "code": "class Solution {\npublic:\n int numberOfWays(string_view corridor) {\n constexpr int MOD = 1000000007;\n int seats = 0;\n uint_fast32_t res = 1;\n int mul = 1;\n for (const char &chr : corridor) {\n if (chr == 'S') {\n if (seats == 2) {\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
0
{ "code": "class Solution {\npublic:\n int numberOfWays(string corridor) {\n const int MOD = 1e9 + 7;\n long long result = 1;\n int seats = 0;\n int plants = 0;\n \n for (char c : corridor) {\n if (c == 'S') {\n if (seats == 2) {\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
0
{ "code": "class Solution {\npublic:\n int numberOfWays(string corridor) {\n int MOD = 1e9 + 7, n = corridor.size(), ans = 1, n_plants = 0, idx = 0;\n\n // the first divider is already installed - simply skip the plants.\n while(idx < n and corridor[idx] != 'S') idx++;\n // we did not f...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
0
{ "code": "class Solution {\npublic:\n int numberOfWays(string str) {\n int n = str.size() ;\n long long ans=1;\n\n long long last=-1;\n int count=0;\n for(int i=0;i<n;i++)\n {\n \n if(str[i]=='P')\n {\n continue;\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
1
{ "code": "typedef long long ll;\nconst ll mod=1e9+7;\nclass Solution {\npublic:\n ll dp[100001][3];\n ll f(string &s,ll i,ll n,ll cnt){\n if(i==n && cnt==2)return 1;\n if(i==n)return 0;\n if(dp[i][cnt]!=-1)return dp[i][cnt]%mod;\n if(s[i]=='S' && cnt==2){\n return dp[i][c...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
1
{ "code": "class Solution {\npublic:\n int numberOfWays(string corridor) \n {\n string s=corridor;\n long res = 1, j = 0, k = 0, mod = 1e9 + 7;\n for (int i = 0; i < s.size(); ++i) {\n if (s[i] == 'S') {\n if (++k > 2 && k % 2 == 1)\n res = res ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
1
{ "code": "class Solution {\npublic:\n // Store 1000000007 in a variable for convenience\n const int MOD = 1e9 + 7;\n \n // Count the number of ways to divide from \"index\" to the last index\n // with \"seats\" number of \"S\" in the current section\n int count(int index, int seats, string& corrido...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
1
{ "code": "class Solution {\npublic:\n unordered_map<string, int> dp;\n int c = 1000000007;\n int util(string &corridor , int start, int chairs, int n, int cache[][3]){\n if(start == n){\n return chairs == 2 ? 1 : 0;\n }\n\n if(cache[start][chairs] != -1){\n return cache[start...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
2
{ "code": "class Solution {\npublic:\n int numberOfWays(string corridor) {\n std::uint64_t ways = 1;\n std::vector<int> gaps;\n int start = -1;\n int seats = 0;\n for (std::size_t i = 0; i < std::size(corridor); ++i) {\n if (corridor[i] == 'S') {\n ++sea...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
2
{ "code": "const int MOD = 1e9+7;\nconst int MAX = 1e5+5;\nclass Solution {\npublic:\n string corr;\n int n;\n int dp[MAX][4];\n int solve(int i,int c){\n if(i==n){\n return c==2;\n }\n if(~dp[i][c]) return dp[i][c];\n c+=(corr[i]=='S');\n if(c<2) return dp[i]...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
2
{ "code": "class Solution {\n public:\n auto numberOfWays(const std::string& corridor) -> int {\n std::vector<int> pos;\n for (int i = 0; i < static_cast<int>(corridor.size()); ++i) {\n if (corridor[i] == 'S') {\n pos.push_back(i);\n }\n }\n if (pos.size() % 2 == 1 || pos.size() == 0) {\...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
2
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int help(int i,string &s,vector<int> &dp){\n if(i>=s.length()) {\n return 1;\n }\n if(dp[i]!=-1) return dp[i];\n int seat=0;\n long long ans=0;\n for(int ind=i;ind<s.length();ind++){\n if(s[in...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
2
{ "code": "int mod=1e9+7;\nint solve(int i,vector<int>&v,string &s,vector<int>&dp)\n{\n if(i==v.size()-1)\n {\n return 1;\n }\n if(dp[i]!=-1)\n return dp[i];\n long long ways=(solve(i+1,v,s,dp)%mod);\n for(int k=v[i]+1;k<s.size();k++)\n {\n if(s[k]=='S')\n break;\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
2
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n \n int numberOfWays(string corridor) {\n vector<int> pos_seats;\n \n for (int i = 0; i < corridor.size(); i++) {\n if (corridor[i] == 'S') {\n pos_seats.push_back(i);\n }\n }\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int numberOfWays(string s) {\n vector<int> numbers ;\n int mod = 1e9 + 7 ; \n int temp = 0 ; \n int plant = 0 ; \n for(int i=0;i<s.length();i++){ \n if(s[i] == 'S'){\n numbers.push_back(i) ;\n }\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <string>\n#include <sstream>\n#include <set>\n#include <map>\n#include <unordered_map>\n#include <unordered_set>\n#include <algorithm>\n#include <stack>\n#include <queue>\n#include <cmath>\n#include <cctype>\n#include <iomanip>\nusing namespace std;\ntypedef...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "/*\nclass Solution {\n int mod = 1e9+7;\n int solve(int i, int j , string &corridor,int count , vector<int> &dp){\n int n = corridor.size();\n if (i>j) {\n return 1;\n }\n if(dp[i]!= -1){\n return dp[i];\n }\n int ans = 0;\n count ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int numberOfWays(string corridor) {\n int n=corridor.length();\n vector<int>prefixCnt(n,0);\n prefixCnt[0]=(corridor[0]=='S')?1:0;\n for(int i=1;i<n;i++){\n if(corridor[i]=='S'){\n prefixCnt[i]=prefixCnt[i-1]+1;\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int numberOfWays(string corridor) {\n int n = corridor.length();\n vector<int> prefixCnt(n, 0);\n prefixCnt[0] = (corridor[0] == 'S') ? 1 : 0;\n for (int i = 1; i < n; i++) {\n if (corridor[i] == 'S') {\n prefixCnt[i] = pr...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "#define ll long long\n#define MOD 1000000007\nclass Solution {\npublic:\n int numberOfWays(string corridor) {\n ll n = corridor.size();\n vector<ll> seat_idx;\n ll seatCount = 0;\n for(ll i = 0; i<corridor.size(); ++i) {\n if(corridor[i] == 'S') {\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "#define ll long long\n#define M 1000000007\n\nclass Solution {\n\n ll multiply(ll a, ll b) {\n return ((a*b)%M +M)%M;\n }\n\npublic:\n int numberOfWays(string corridor) {\n while (!corridor.empty() && corridor.back() == 'P') corridor.pop_back();\n reverse(corridor.begin(), cor...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int MOD = 1e9 + 7;\n\n void precomputeNextIdx(const vector<int>& pref, vector<int>& next_idx) {\n int n = pref.size();\n for (int i = 0; i < n; ++i) {\n int limit = (i > 0) ? pref[i - 1] + 2 : 2;\n // Binary search for the first index wi...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int MOD = 1e9 + 7;\n\n void precomputeNextIdx(const vector<int>& pref, vector<int>& next_idx) {\n int n = pref.size();\n for (int i = 0; i < n; ++i) {\n int limit = (i > 0) ? pref[i - 1] + 2 : 2;\n // Binary search for the first index wi...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\nprivate:\n vector<vector<int>> dp;\n int Mod = 1e9+7;\npublic:\n int Memo(string& c,int index,int cnt){\n if(index==c.size() && cnt==0) return 1;\n if(index>=c.size()) return 0;\n if(dp[cnt][index]!=-1) return dp[cnt][index];\n if(cnt!=0){\n if(...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int f(int i, string& corridor, int seats, vector<vector<int>>& dp)\n {\n int n=corridor.length();\n if(i>=n)\n {\n if(seats==2)return 1;\n return 0;\n }\n if(dp[seats][i]!=-1)return dp[seats][i];\n int ways=0;...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\nint MOD=1e9+7;\n int numberOfWays(string corridor) {\n int f=0;\n for(auto ch:corridor){\n if(ch=='S') f++;\n }\n if(f%2 or f==0) return 0;\n vector<vector<int>> rec;\n int n=corridor.size();\n int i=0;\n while(i<n){\n if(corridor[i]=='S')...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int numberOfWays(string s) {\n int n = s.length();\n int totalS = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'S') {\n totalS++;\n }\n }\n if (totalS == 2) {\n return 1;\n }\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "\n#pragma GCC optimize(\"Ofast\",\"inline\",\"fast-math\",\"unroll-loops\",\"no-stack-protector\")\n\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\",\"f16c\")\n\nstatic const auto fast = []() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; } ();\n\...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int MOD = 1e9+7;\n int numberOfWays(string corridor) {\n int n = corridor.size();\n vector<vector<int>>dp(n + 1, vector<int>(3));\n\n dp[n][0] = 0;\n dp[n][1] = 0;\n dp[n][2] = 1;\n\n for(int i = n-1; i>=0; i--) {\n if(c...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n// int dp[100001][3];\n// int f(int i,int c,string corridor,int n){\n// if(i>=n){\n// if(c==2) return 1;\n// else return 0;\n// }\n// if(dp[i][c]!=-1){\n// return dp[i][c];\n// }\n// if(c==0){\n// if(corridor[i]=='S'){\n// ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n\n int numberOfWays(string s) {\n\n int n = s.size();\n\n vector<vector<int>> dp(n+1, vector<int>(3, 0));\n dp[n][2] = 1;\n\n for(int idx=n-1; idx>=0; idx--) {\n for(int cnt=2; cnt>=0; cnt--) {\n \n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\nint M = 1e9+7;\n int f(int ind, int seats, string &s, vector<vector<int>> &dp){\n if(ind == s.size()){\n if(seats==2) return 1;\n else return 0;\n }\n if(dp[ind][seats]!=-1) return dp[ind][seats];\n int ways1 = 0, ways2 = 0;\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "#define a 1000000007\nclass Solution {\npublic:\n\n int recursive(string& corridor, int ind, int count,vector<vector<int>>& dp){\n if(ind==corridor.size()-1){ \n if(corridor[ind]=='S') count++;\n if(count==2) return 1;\n return 0;\n }\n\n if(dp[ind][...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n vector<vector<int>> dp;\n int solve(string& s,int i,int currSeat){\n if(i==s.size()){\n return currSeat==2?1:0;\n }\n if(dp[i][currSeat]!=-1)return dp[i][currSeat];\n int res=0;\n if(currSeat==2){\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int n;\n int mod = 1e9+7;\n\n vector<vector<int>> memo;\n\n int solve(string& s, int idx, int cnt) {\n\n if(idx == n) return (cnt == 2);\n\n if(memo[idx][cnt] != -1) return memo[idx][cnt];\n\n int ans = 0;\n\n if(cnt == 2) {\n i...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\n int mod;\n int helper(string& corridor, int idx, int cnt, vector<vector<int>>& dp) {\n int ans = 0;\n\n if (corridor.length() == idx) {\n if (cnt == 2)\n return 1;\n return 0;\n }\n\n if (dp[idx][cnt] != -1)\n ...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int n;\n int mod = 1e9+7;\n\n vector<vector<int>> memo;\n\n int solve(string& s, int idx, int cnt) {\n\n if(idx == n) return (cnt == 2);\n\n if(memo[idx][cnt] != -1) return memo[idx][cnt];\n\n int ans = 0;\n\n if(cnt == 2) {\n i...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int n;\n int mod = 1e9+7;\n\n vector<vector<int>> memo;\n\n int solve(string& s, int idx, int cnt) {\n\n if(idx == n) return (cnt == 2);\n\n if(memo[idx][cnt] != -1) return memo[idx][cnt];\n\n int ans = 0;\n\n if(cnt == 2) {\n i...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int solve(int index,int count,string &s,vector<vector<int>>&dp){\n // base case\n if(index>=s.size()){\n if(count==2)\n return 1;\n else\n return 0;\n }\n if(count>2)\n return 0...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>dp;\n const int mod = 1e9+7;\n int numberOfWays(string str) {\n dp.resize(str.length(),vector<int>(4,-1));\n int idx = 0;\n int count = 0;\n return fun(idx,str,count)%mod;\n }\n long long int fun(int idx , string &st...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n int MOD=1e9+7;\n int helper(int index, int seats, string &corridor, vector<vector<int>> &dp)\n {\n if(index==corridor.length())\n {\n if(seats==2)\n return 1;\n return 0;\n }\n if(dp[index][seats]!=-1) ret...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic:\n\nint solve(int i,int ct, string &corridor,vector<vector<int>>&dp){\n if(i>=corridor.size()) return ct==2;\n if(dp[i][ct]!=-1) return dp[i][ct];\n int ans=0;\n if(ct==2){\n if(corridor[i]=='P'){\n ans=(solve(i+1,ct,corridor,dp)+solve(i+1,0,corridor,dp));\n } else{\...
2,251
<p>Along a long library corridor, there is a line of seats and decorative plants. You are given a <strong>0-indexed</strong> string <code>corridor</code> of length <code>n</code> consisting of letters <code>&#39;S&#39;</code> and <code>&#39;P&#39;</code> where each <code>&#39;S&#39;</code> represents a seat and each <c...
3
{ "code": "class Solution {\npublic: \n int generate(const string &corridor, int i, int prev)\n {\n if (i == corridor.size())\n {\n if (prev == 2)\n {\n return 1;\n }\n else\n {\n return 0;\n }\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n std::stable_partition(nums.begin(), nums.end(), [](auto num) {\n return num >= 0;\n });\n const int middle = nums.size() / 2;\n for (int idx = 1; idx < nums.size(); ++idx) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n std::stable_partition(nums.begin(), nums.end(), [](auto num) {\n return num >= 0;\n });\n const int middle = nums.size() / 2;\n for (int idx = 1; idx < nums.size(); ++idx) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n stable_partition(nums.begin(), nums.end(), [](auto num) {\n return num >= 0;\n });\n const int middle = nums.size() / 2;\n for (int idx = 1; idx < nums.size(); ++idx) {\n const...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n\n int pos=0,neg=1;\n vector<int>ans(nums.size(),0); \n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n ans[pos]=nums[i]...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int>result(nums.size(),0);\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int posindex=0;\n int negindex=1;\n for(int i=0;i<nums.size();i++){\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int>result(nums.size(),0);\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int posindex=0;\n int negindex=1;\n for(int i=0;i<nums.size();i++){\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n int pos=0;\n int neg=1;\n vector<int> result(nums.size());\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n res...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n\n int posIdx = 0, negIdx = 1;\n vector<int> ans(nums.size());\n \n for (int num: nums) {\n if (num < 0) {\n ans[negI...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);\n vector<int> ans(nums.size());\n int posindex=0;\n int negindex=1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n ans[posindex]=nu...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n vector<int> ans(nums.size());\n int posIdx = 0;\n int negIdx = 1;\n\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] > 0) {...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n = nums.size();\n vector <int> ans(n, 0);\n int pos = 0;\n int neg = 1;\n for(int i = 0; i < n; i++){\n if(nums[i] < 0){\n ans[neg] = nums[i];\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int pos=0,neg=1;\n vector<int> a=nums;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]<0)\n {\n a[neg]=nums[i];\n neg+=2;\n }\n else\n {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n \n int n = nums.size();\n vector <int>arr(n,0);\n int even =0;\n int odd =1;\n for(int i =0 ;i<n;i++){\n if(nums[i] <0 ){\n arr[odd] =nums[i];\n odd+=2...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n // it pos neg\n int pos=0,neg=1;\n vector<int> ans(nums.size(),0);\nfor(int i=0;i<nums.size();i++){\n if(nums[i]<0){\n ans[neg]=nums[i];\n neg+=2;\n }\n else{\n ans[pos]=nums[...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int>vec(nums.size(),0);\n int i=0;\n int j=1;\n for(int n: nums){\n\n if(n>0){\n vec[i]=n;\n i+=2;\n }\n else{\n vec[j]=n;...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int pi = 0;\n int ni = 1;\n vector<int> res(nums.size(), 0);\n\n for (int n : nums) {\n if (n > 0) {\n res[pi] = n;\n pi += 2;\n } else {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
0
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int pcnt=-1,ncnt=-1;\n vector<int> ans(nums.size());\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n pcnt++;\n ans[2*pcnt] = nums[i];\n }\n els...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n=nums.size();\n vector<int> ans(n,0);\n int pos=0,neg=1;\n for(int i=0;i<n;i++){\n if(nums[i]<0){\n ans[neg]=nums[i];\n neg+=2;\n }else{\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int temp[nums.size()];\n int a=0,b=1;\n for(int i =0;i<nums.size();i++){\n if(nums[i]>=0){\n temp[a]=nums[i];\n a = a+2;\n }\n else{\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n\n\n\n\nint n = nums.size();\n\n\n int ans[n];\n int m = 0;\n int l = 1;\n for (int i = 0; i < n; i++)\n {\n \n if (nums[i] >= 0 && m < n)\n {\n\n ans[m] = nums[i];\n\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n = nums.size();\n int arr[n];\n // int n = nums.size();\n int left=0;\n int right =1;\n for( int i=0;i<n;i++){\n if( nums[i]>=0){\n arr[left] = nums[...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) \n{\n // Dekho bhaiya, basic idea yeh hai ki array mein equal number of positive aur negative elements hai,\n // toh hum do alag arrays banaenge, ek mein positive aur doosre mein negative elements rakh lenge.\n // Jaise o...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int arranged[nums.size()];\n int pos = 0, neg = 1;\n for (size_t i = 0; i < nums.size(); i++) {\n if (nums[i] > 0) {\n arranged[pos] = nums[i];\n pos += 2;\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int nc = 0, k = 0,z=0;\n int n = nums.size();\n for (int i = 0; i < n; i++) {\n if (nums[i] < 0)\n nc++;\n }\n int pc = n-nc;\n int pos[pc], neg[nc];\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "int speedup = []{\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n std::cout.tie(0);\n return 0;\n}();\n\n\nclass Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int> result (nums.size());\n int i = 0 , j = 1;\n \n for(int k = 0 ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "static const auto x = []() {\n\tstd::ios::sync_with_stdio(false);\n\tstd::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int posIdx = 0, negIdx = 1;\n vector<int> ans(nums.size());\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n = nums.size();\n vector<int> res(n);\n int pos = 0, neg = 1;\n for(const int& it : nums){\n if(it >= 0){\n res[pos] = it;\n pos+=2;\n }else{...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int> ans(nums.size());\n int pos = 0;\n int neg = 1;\n\n for(int i=0; i<nums.size(); i++)\n {\n if(nums[i] > 0)\n {\n ans[pos] = nums[i];\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n // if(nums[0]<0){\n // long long j = 1;\n // while(j<nums.size()){\n // if(nums[j]>=0 && nums[0]<0){\n // long long item = nums[j];\n // ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int i=0;\n int j=0;\n int n=nums.size();\n long int neww[200000]={0};\n while(i<n/2 && j<n){\n if(nums[j]>0){\n neww[i]=nums[j];\n i++;\n j++; \n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n = nums.size();\n int pos[n/2], neg[n/2];\n\n int p = 0, q = 0;\n\n for(int i=0; i<n; i++) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n auto neg = stable_partition(nums.begin(), nums.end(), [](int n){ return n > 0; });\n auto pos = nums.begin();\n vector<int> res(nums.size());\n size_t i = 0;\n while (neg != nums.end()) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n auto neg = stable_partition(nums.begin(), nums.end(), [](int n){ return n > 0; });\n auto pos = nums.begin();\n vector<int> res(nums.size());\n for (size_t i = 0; neg != nums.end(); ) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int pt1 = 0;\n queue<int> posQ, negQ;\n while(pt1 < nums.size()) {\n if(pt1%2 == 0) {\n //postitive number\n if(nums[pt1] == 0) {\n if(!posQ.empty()) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n \n\n\n queue<int>q;\n int n=nums.size();\n\n for(int i=0;i<n;i++){\n\n if(nums[i]<=0) {\n q.push(nums[i]);\n }\n\n }\n \n vector<int>ans...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int pt1 = 0;\n queue<int> posQ, negQ;\n while(pt1 < nums.size()) {\n if(pt1%2 == 0) {\n //postitive number\n if(nums[pt1] == 0) {\n if(!posQ.empty()) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int pt1 = 0;\n queue<int> posQ, negQ;\n while(pt1 < nums.size()) {\n if(pt1%2 == 0) {\n //postitive number\n if(nums[pt1] == 0) {\n if(!posQ.empty()) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "#include <vector>\nclass Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n int n = nums.size();\n vector<int> positive(n/2);\n vector<int> negative(n/2);\n int i = 0, j = 0;\n for(int...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n=nums.size();\n\n int *arr=new int[n];\n int i=0;\n int j=1;\n int index=0;\n while(index<n){\n if(nums[index]>=0){\n arr[i]=nums[index];\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n cin.tie(nullptr) -> sync_with_stdio(false);\n int n = nums.size();\n // vector for positive element\n vector<int> v1(n/2);\n int count1 = 0;\n for(int i=0; i<n; i++){\n if(n...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n cin.tie(nullptr) -> sync_with_stdio(false);\n int n = nums.size();\n \n vector<int> v1(n/2); // vector for positive element\n vector<int> v2(n/2); // vector for negative element\n int...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int>ans=nums;\n int k=0,j=0;\n for(int i=0;i<ans.size();i++)\n {\n if(ans[i]>=0)\n {\n nums[2*j]=ans[i];\n j++;\n }\n else...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int s=nums.size();\n vector<int> a(s); \n int p=0;\n int n=1; \n for (int i = 0; i < nums.size(); i ++){\n if (nums[i]>0){\n a[p]=nums[i];\n p+=2; \n...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n=nums.size();\n vector<int> temp(n);\n int k=0,j=1;\n for(int i=0;i<n;i++){\n if(nums[i]<0){\n temp[j]=nums[i];\n j=j+2;\n }\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int> negatives;\n\n int low = -1;\n for(int i = 0; i < nums.size(); i++) {\n if(nums[i] > 0) {\n swap(nums[i], nums[++low]);\n } else {\n negative...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n int start=0,end=0;\n vector<int> vec;\n while(end<nums.size()&&start<nums.size()){\n while(start<nums.size()&&nums[star...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n queue<int> q1;\n queue<int> q2;\n for(int i = 0; i< nums.size();i++){\n if(nums[i] >= 0){\n q1.push(nums[i]);\n }\n else{ \n q2.push(nums[i]);...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n queue<int> qp,qn;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0){\n qp.push(nums[i]);\n }\n else{\n qn.push(nums[i]);\n }\n }\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int N=nums.size();\n vector<int> ans;\n int p=0;\n int n=0;\n \n while(p<N && n<N){\n while(p<N && nums[p]<0) p++;\n while(n<N && nums[n]>0) n++;\n if(...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n/* if(nums[i]<0 && nums[j]>=0){\n swap(nums[i], nums[j]);\n i+=2;\n j+=2;\n }\n else if(nums[i] >= 0 && i < nums.size()) i+=2;\n else if(nums[j] < 0 && j < nums.size()) j+=2;\n*/\n vector<int> r...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int> ans;\n int i=0,j=0;\n int n=nums.size();\n while(i<n && j<n){\n while(nums[i]<0){\n i++;\n }\n while(nums[j]>0){\n j++;\n }\n ans.push_back(nums[i]);\n i++;\n ans.push...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int n=nums.size();\n vector<int> v;\n int pv=0;\n int nv=0;\n\n while(pv<=n-1 && nv<=n-1){\n if(nums[pv]>0){\n v.emplace_back(nums[pv++]);\n }\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int f1 = 0,f2 = 0;\n int i = 0,j = 0;\n int n = nums.size();\n vector <int> ans;\n while(i < n) {\n while(!f1 && i < n) {\n if(nums[i] >= 0) {\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n vector<int> neg;\n int index=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<0){\n neg.push_back(nums[i]);\n }else{\n nums[index++]=nums[i];\n ...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n // Count the number of positive and negative numbers\n int posCount = 0, negCount = 0;\n for (int i : nums) {\n if (i > 0) posCount++;\n else negCount++;\n }\n\n // All...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n // Count the number of positive and negative numbers\n int posCount = 0, negCount = 0;\n for (int i : nums) {\n if (i > 0) posCount++;\n else negCount++;\n }\n\n // All...
2,271
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length consisting of an <strong>equal</strong> number of positive and negative integers.</p> <p>You should return the array of nums such that the the array follows the given conditions:</p> <ol> <li>Every <strong>c...
2
{ "code": "class Solution {\npublic:\n vector<int> rearrangeArray(vector<int>& nums) {\n int a[nums.size()];\n int k=0,j=1;\n for(int i=0;i<nums.size();i++){\n if(nums[i]>0) {a[k]=nums[i];k+=2;}\n else {a[j]=nums[i];j+=2;}\n }\n vector<int> v;\n for(i...