Interview Aptitude Question
Given a linked list of infinite length. Write a
function to return a random node.
Constraints:
1 You
can traverse a singly linked list only once.
2 You
can not use any extra space.
3. You
don't know the length of the linked list in advance.
Probable solution:
For
each node in the linked list, generate a random number and as u traverse it
keep track of the node address which is allotted minimum random number and then
finally return that node's address as the ans.