Question: Winzo Gaming, Online Assessment (BITS Pilani | FTE ) | Eliminate the numbers in a Circle | Special Sum | Lazy Ankur
1
Entering edit mode

ADD COMMENTlink 16 months ago PoGo 2.4k
1
Entering edit mode

int fun(int n)
{
    queue<int> q;
    if(n==1)
    return 1;
    for(int i=1;i<=n;i++) q.push(i);
    while(q.size()!=1)
    {q.pop();q.push(q.front());q.pop();}
    return q.front();
}

ADD COMMENTlink 15 months ago AT • 10
0
Entering edit mode

int fun(vector<int>& vec, int n, int l, int r)

{

vector<int> ans;

for(int i=0;i<vec.size()-1;i++)

{int sum=0;

for(int j=i;j<vec.size()-1;j++){

sum+=vec[j];ans.push_back(sum);}

}

sort(ans.begin(),ans.end());

long long a=10;

return accumulate(ans.begin()+l-1,ans.begin()+r,a)%1000000007;

}

ADD COMMENTlink 15 months ago AT • 10
0
Entering edit mode

void rangeSum(string &s,int i,unordered_set<string> &set,char prev) 
{
    if(i==s.size())
    {set.insert(s);return;}
    char curr=s[i]++;
    rangeSum(s,i+1,set,curr);
    if(i-1>=0)
    {s[i]=prev-1;rangeSum(s,i+1,set,curr+1);s[i]=curr-1;}
    if(i+1<s.size())
    {s[i]=s[i+1]+1;rangeSum(s,i+1,set,curr-1);s[i]=curr+1;}
}

int rangeSum(string s) 
{   
    unordered_set<string> set;
    rangeSum(s,0,set,'z');
    return set.size();
}

ADD COMMENTlink 15 months ago AT • 10
0
Entering edit mode

{
    vector<int> v(s.size(),1);
    for(int i=0;i<s.size();i++)
    {if(i>0 && s[i+1]!=s[i]+1)
    v[i]+=2;
    if(i<s.size()-1 && s[i-1]!=s[i]-1)
    v[i]+=1;}
    
    int ans=1;
    for(auto x: v)
    {ans=ans*x%;}
    return ans;
}

ADD COMMENTlink 15 months ago AT • 10

Login before adding your answer.

Similar Posts
Loading Similar Posts