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. This function is used to perform a number of right circular rotations and return the value of the element at a given index. 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;
}
The remaining code can be found here link