Read the Kth Value From the End of a Doubly Linked List
easyQuestion 564A singly linked list can only be read from the front, so reaching a value counted from the end means working out its position first. A doubly linked list can start at tail and follow prev, which makes the last few values the cheapest ones to reach.
Requirements:
1. getFromEnd(int k) returns the value k steps before the last node, so k = 0 is the last value and k = 1 is the one before it.
2. It returns -1 when k is negative or is not less than size, which also covers an empty list.
3. Start at tail and follow prev. Do not walk from head.
The DNode class is provided. Do not rename it and do not add public to it, because a Java source file may contain only one public class.
Do NOT write a main method.
Expected output
40 30 10
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...