Neighbour sums ring

Write codeMedium14 min

Your task

Storage lockers are arranged in a ring, so the last locker sits next to the first. Given the parcel count in each locker (in ring order), return a list where position i holds the combined count of locker i's two neighbours: the one before and the one after, wrapping around the ends. With a single locker, both neighbours are that locker itself. Example: [1, 2, 3, 4] gives [6, 4, 6, 4].

Examples

ring_neighbor_sums(counts: list[int]) -> list[int]
Example 1
Inputring_neighbor_sums([1, 2, 3, 4])
Output[6, 4, 6, 4]