Please help me why my code is showing the segmentation fault

Please give clear explanation of why my code was giving error along with other examples where you have seen these type of errors. That way I can make sure it won’t repeat again .

Hey @hemu1999

	for(int i=0;i<n-1;i++){ //here i<n-1 instead of k because n nodes h and u already took 1 in head
		int temp;
		cin >> temp;
		cur->next = new Node(temp);
		cur = cur->next;
	}
	head = remove_k_node(head,k-1); //here k-1  

Above things are self explanatory.
If this resolves your query then please mark it as resolved :slight_smile:

Hello kartik, I’m new to c++, I generally use python, since cb doesn’t support py, I"m using c++ could you please expalin &gt all those clearly

Hey I did 2 changes only
1st one was taking n-1 nodes because u have to take n nodes as input and u already took 1 from the user in head
So balance left was n-1
And u used k there instead.

2nd change was deleting k-1 node from last instead of k because ur code was considering k starts from 0
But it actually starts from 1

Who said u can’t write code in python
U can change language in the IDE or wherever u are writing code

still not resolved, what should i do?

What do u mean ? Is it still not working ?