My issue
Explain constraints of the problem.
How I know it is single loop problem or double loop?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
long long N;
cin>>N;
int M;
cin>>M;
long long a[N]={0};
long long b[N]={0};
for(int i=0;i<N;i++)
{
a[i]=i+1;
b[i]=i+N+1;
}
long long c[N*N];
int k=0;
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
c[k++]=a[i]+b[j];
}
}
sort(c,c+(N*N));
long long q;
map<int,int>mp;
for(int i=0;i<N*N;i++)
{
mp[c[i]]++;
}
for(int i=0;i<M;i++)
{
cin>>q;
if(mp[q])
cout<<mp[q]<<endl;
else
cout<<0<<endl;
}
}
Problem Link: Sum Queries Practice Coding Problem