plaintext
function xenia_ringroad(n, tasks)
current := 1
total_time := 0
for each target in tasks
if target >= current then
total_time := total_time + (target - current)
else
total_time := total_time + (n - current + target)
current := target
return total_time
The loop processes each task in the vector. For each target, you calculate how many houses you need to pass. The if statement handles both cases: moving forward normally and wrapping around the ring. After each move, you update your position. The time complexity is where is the number of tasks. You visit each task exactly once.