Kindly find the error in these codes.
Error in other approaches
in the first code, the errror that u are commiting is that you are deleting the head reference, so the head is no longer pointing to a valid refernce, since the head is being removed and all this is being done by passing refernce of head, try it by using pointer that is different from head, and assign it to a new_head pointer which points to head of newly formed linked list
@sr30
Problem with the 2nd code is that u are erasing the element and also the iterator no longer points to the next element in the list container
try out this approach
and its ok that u are practising stl but interview point of view, no one is checking ur stl knowledge they`ll check if u are able to do pointer manipulation in this particular q. This is a standard question to check efficiency of handling pointers by the candidate
I recommend that u try out pointer manipulation for this quesstion
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.