126. Insert at a Position
Build the list, then read two values on the next line: a position p and a
value k.
Insert a new node holding k so that it ends up at 0-based position p, and print the
resulting list.
If p is 0 the node goes at the front. If p equals the length, it goes at the end. If
p is beyond the length, print Invalid and change nothing.
Constraints - `0 ≤ n ≤ 100000` - `0 ≤ p ≤ 200000` - `-1000000 ≤ value, k ≤ 1000000`
Input
The first line contains an integer n, the number of nodes.
The second line contains n space-separated integers — the node values from head to tail.
The starter code builds the list for you; work on the nodes, not the array.
The third line contains two integers p and x — the 0-based position and the value to insert there.
Output
Print the resulting list from head to tail, separated by single spaces, or Invalid if p is beyond the length.