this is an interview question and I was trying to solve it.
I completely solved and I realized that I missed one test case.
The question is , how would you delete a second occurrence of a node in a linklist.
FOr example:
1->2->9->5->2 and I enter 2.
so the out put should be 1->9>5->2
I did solve using two pointers first and second which will keep on swaping based on the findings.
And I am always storing the previous pointer. for example in above example I am storing at 1 and 5. so that I could always delete the next one.
But what if the linklist becomes like this:
2->7->9->2
and the out out has to be 7->9->2.
Do let me know, if you guys have any questions?
1 Answer