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.
An intuitive explanation would be: just imagine the two pointers, current and result as sprinters. If each node represented a milestone and let it takes for them to move between consecutive stones 1 second, thus both have equal speeds(imagine index represents time passage starting from index = 0 when refree fired his gun.). Hence in each iteration, the two would move from starting point to next adjacent milestone. When current reaches the last milestone, result must be at positionfromtail milestone and because both move with equal speeds it means that current must have a headstart of positionfromtail seconds over result. Clearly, result must start moving (result=result->next) only after time greater than positionfromtail (index++>positionfromtail).
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 →
An intuitive explanation would be: just imagine the two pointers, current and result as sprinters. If each node represented a milestone and let it takes for them to move between consecutive stones 1 second, thus both have equal speeds(imagine index represents time passage starting from index = 0 when refree fired his gun.). Hence in each iteration, the two would move from starting point to next adjacent milestone. When current reaches the last milestone, result must be at positionfromtail milestone and because both move with equal speeds it means that current must have a headstart of positionfromtail seconds over result. Clearly, result must start moving (result=result->next) only after time greater than positionfromtail (index++>positionfromtail).