class Solution {
public:
int minSubArrayLen(int target, vector<int>& nums) {
int ant=0,mi=1000005;
int q[100009];int hh=0,tt=-1;
for(int i=0;i<nums.size();i++)
{
q[++tt]=nums[i];
ant+=nums[i];
while(hh<=tt&&ant>=target)
{
mi=min(mi,tt-hh+1);
ant-=q[hh];
hh++;
}
}
if(mi==1000005)return 0;
return mi;
}
};
class Solution {
public:
int balancedString(string s) {
unordered_map<char,int> m;
int mi=100005;
for(auto i:s)m[i]++;
int l=s.size(),cl=l/4;
if(m['Q']==cl&&m['W']==cl&&m['E']==cl&&m['R']==cl)
return 0;
for(int i=0,j=0;i<l;i++)
{
m[s[i]]--;
while(m['Q']<=cl&&m['W']<=cl&&m['E']<=cl&&m['R']<=cl)
{
mi=min(mi,i-j+1);
m[s[j]]++;
j++;
}
}
return mi;
}
};
class Solution {
public:
int findLengthOfShortestSubarray(vector<int>& arr) {
int n=arr.size(),r=n-1;
while(r&&arr[r-1]<=arr[r])r--;
if(r==0)return 0;
int ant=r;
for(int i=0;i==0||arr[i-1]<=arr[i];i++)
{
while(r<n&&arr[r]<arr[i])r++;
ant=min(ant,r-i-1);
}
return ant;
}
};
class Solution {
public:
vector<int> shortestSeq(vector<int>& big, vector<int>& small) {
int lb=big.size(),ls=small.size();
int ant=100005;vector<int> answer;
if(ls>lb)return {};
unordered_map<int,int> ms;
int lendif=0;
for(int i=0;i<ls;i++)
{
ms[small[i]]++;
lendif++;
}
for(int i=0,j=0;i<lb;i++)
{
if(ms.find(big[i])!=ms.end()&&--ms[big[i]]>=0)--lendif;
while(lendif==0)
{
if(i-j+1<ant)
{
ant=i-j+1;
answer={j,i};
}
if(ms.find(big[j])!=ms.end()&&++ms[big[j]]>0)++lendif;
++j;
}
}
return answer;
}
};