Example:
Sample Input :
Link list :10->20->100->30->50->5->70->234
Given K : 3
Sample Output:
5->70->234->10->20->100->30->50
Algo:
- Take two pointer both pointing head at beginning.
- Move firstPointer to K node.
- Now move both first and second pointer while firstPointer != null.
- Here secondPointer will point to Kth Node from Last.
- Make node of secondPointer as head of Link list.
Source Code:
No comments:
Post a Comment