Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
859 views
in Online Assessments by Expert (108,280 points) | 859 views

2 Answers

0 like 0 dislike
Best answer

image

 

image

 

Do share your approach guys

by Expert (108,280 points)
selected by
0 like 0 dislike

Just try to think mathematically and you will get it

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}

signed main()
{

    int n;
    cin >> n;
    int neg = 0, pos = 0;
    for (int i = 0; i < n; i++)
    {
          int x;
          cin >> x;
          if (x < 0)
           neg++;

          else if (x > 0)
                pos++;
    }

    if (neg == 0)
    {
          cout << 0;
    }
    else
    {
          int ans = mul(exp(2, neg - 1), exp(2, pos));

          cout << ans;
    }
}
by Expert (108,280 points)
edited by