Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
1,496 views
in Online Assessments by Expert (144,420 points)

2 Answers

0 like 0 dislike
 
Best answer

image

 

image

 

Do share your approach guys

by Expert (144,420 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 (144,420 points)
edited by
...