Need help, Practice question , I'm getting SIGSEGV error

#include <iostream>
using namespace std;

int main() {
    int t,n;
        std::vector<int> x ;
        vector<int> a;
        int i;
        int j;
        for (i=0;i<n-1;i++){
        for (j=i+1;j<n;j++){
            int l=abs(x[i]-x[j]);
            if(std::find(a.begin(),a.end(),l)==a.end() && a[a.size()-1]!=l)
	// your code goes here
	std::cout << a.size() << std::endl;
	return 0;

Which question?

use html or markdown to present your question , mention the links to the question and your code . this will help you in getting a solution to your problem quickly.

I think this error is because while take input with cin you have put parentheses around the variable.Try removing those, then may be this error would not occur
or try removing the std keyword as you have already defined it with namespace

as far as i know, you are not allowed to access X[i]( x being a vector) if x is not already of size i.
instead try
for(int i = 0; i < n; i++){
int temp;
cin >> temp;
edit :
when you do a[a.size()-1] != l, since a is initially of size 0, you are essentially querying a[-1], which is incorrect. Try doing vector< int > a(1); instead, which makes a initially of size 1.

It is useful to know that SIGSEGV means a runtime error, so you are basically looking for infinite loops, division by 0, invalid memory access etc.
Happy Coding :slight_smile: