Getting segmentation fault(Core Dumped) when big integers are passed.It works fine for smaller inputs.
Replaced int with long int and also tried to declare the variables globally,But still the same error. Here is the function:
vector<long long int> circularArrayRotation(vector<long long int> a, long long int k, vector<long long int> queries) {
vector <long long int> b;
std::vector<long long int> result(queries.size());
b=a;
for(long long int j=0;j<k;j++)
{
for(long long int i=0;i<a.size();i++)
a[i]=b[(a.size()+i-1)%a.size()];
b=a;
}
for(long long int k=0;k<queries.size();k++)
result[k]=a[queries[k]];
for(long long int i=0;i<result.size();i++)
cout<<result[i]<<endl;
return result;
}
Aucun commentaire:
Enregistrer un commentaire