Algorithm to find the mth element from the end of list

Given a singly-linked list, devise a time and space efficient algorithm to find the mth
element from the end of the list.
If m = 0, then your algorithm should return the last element of the list. It should also
take care of boundary conditions. Analyze the time complexity of your algorithm.

Replies

You are reading an archived discussion.

Related Posts

Engineering manager at a structural precast concrete plant in California, USA
#include #define MUL(a,b) a*b #define Pow(a) a*a int main() { int a=3; int b=2; printf("Ans: %d\n", MUL (MUL(a+1,b), Pow(b+1))); return 0; }
If a rotor without stator having 3 phase AC winding and free to rotate, if 3 phase power supply is given to its winding through slip ring, then what happen,...
While Facebook is retiring their 'fShare' button with Facebook Like button, Google has launched a new 'Google+ Share' button to make it easier for people on Google Plus to share...