O(n) Time Solution - Simple and Fast!
ApproachChild 0 holds the ball, and passes it on to Child 1, who passes it on to Child 2, and so on. But whenever it reaches the n-1th child, the direction reve
# Approach
<!-- Describe your approach to solving the problem. -->
Child 0 holds the ball, and passes it on to Child 1, who passes it on to Child 2, and so on. But whenever it reaches the n-1th child, the direction reverses. So, if n = 5, then the sequence will look something like this:

`0 -> 1 -> 2 -> 3 -> 4 -> 3 -> 2 -> 1 -> 0 -> 1 ...`

The key thing to take from this is that it goes from 0 to n, then from n-1 to 1, and then back to 0 again, meaning that we can represent one single cycle as 
```
[a for a in range(n)] + [b for b in range(n-2, 0, -1)]
```

The first part of this, `[a for  a in range(n)]` generates the part from 0 to n-1, and the second part, `[b for b in range(n-2, 0, -1)]` generates the reverse movement of the ball to complete the cycle.

Finally, we should return the item in position: k modulo the length of one complete cycle. This is how to do that:
```
return full_cycle[k%len(full_cycle)]
```


# Complexity
#### ***Time complexity:***

The construction of actual_n involves two list comprehensions:

- [a for a in range(n)], which takes 𝑂(𝑛) time to generate, and

- [b for b in range(n-2, 0, -1)], which takes 𝑂(𝑛) time to generate.

Together, this is 𝑂(𝑛) time.

The modulo operation and indexing into the list take 𝑂(1).

Thus, the overall time complexity is 𝑂(𝑛) due to the list construction.

#### ***Space complexity:***
The list full_cycle has 
- 2𝑛−2 elements, which is 𝑂(𝑛) space.
- A few integer variables are used, which take 𝑂(1) space.

Thus, the overall space complexity is 𝑂(𝑛) due to the storage of the full_cycle list.

# Code
```python3 []
class Solution:
    def numberOfChild(self, n: int, k: int) -> int:
        if n<3: 
            return k%n 
        # For any n lower than 3, then the corresponding list will already loop back on itself.

        full_cycle = [a for a in range(n)] + [b for b in range(n-2, 0, -1)]
        # Generating the complete cycle list

        return full_cycle[k%len(full_cycle)]
        # Finally, we return the item in position k modulo the length of one complete cycle, or our actual_n list.
```
['Python3']