We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I can explain mathematically here.
Suppose we need to find 3nd postion from tail.
This means it is (n-3)+1 position from head(where n is total number of nodes in list)
We dont have n given in our problem statement
while loop is going for n times
So what index variable does here it starts counting after 3. Then obviously it counts n-3. Thats the element we need.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Get Node Value
You are viewing a single comment's thread. Return to all comments →
I can explain mathematically here. Suppose we need to find 3nd postion from tail. This means it is (n-3)+1 position from head(where n is total number of nodes in list)
We dont have n given in our problem statement
while loop is going for n times So what index variable does here it starts counting after 3. Then obviously it counts n-3. Thats the element we need.