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.
Although this is correct solution but this given running time complexity is O(n^2)
Better Solution:
Algorithm
1.find the length of the linkedList by iteraing it. Let length be L.
2.Nth node from the last of the linkedList is L-(N+1) node from the head.
Time Complexity
O(2n) ~ O(n)
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 →
Hi,
Although this is correct solution but this given running time complexity is O(n^2)
Better Solution: Algorithm 1.find the length of the linkedList by iteraing it. Let length be L. 2.Nth node from the last of the linkedList is L-(N+1) node from the head.
Time Complexity O(2n) ~ O(n)