Build a circular linked list · Compiler

Build a circular linked list

Build a circular singly linked list from the given values. Append x after the old tail and link the new tail to the head. Start at the old tail and follow exactly k next links around the updated circle.

Input
Read n k (1 <= n <= 100, 0 <= k <= 1000), then n integer values in order from head to old tail, then x. All values are in [-1000, 1000].
Output
Print the value at the node reached. For zero moves, print the value at the old tail.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…