Insert and Remove at a Position
mediumQuestion 445Both methods share one invariant: to change a link you must be standing on the node BEFORE the target, because a singly linked node cannot see backwards.
Requirements:
1. insertAt(int index, int value) puts a new node at that 0-based position and returns true; it returns false and changes nothing when index is negative or greater than size().
2. removeAt(int index) unlinks the node at that position and returns its value, or -1 when index is negative or not less than size().
3. Index 0 means the head in both methods.
The Node 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
true 10 -> 15 -> 20 -> 30 -> null true 10 -> 15 -> 20 -> 30 -> 40 -> null false 5
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...