Simple and Easy Solution ( Runtime beats 100% and Memory beats 89%)
IntuitionThe problem involves passing a ball among n children arranged in a line. The ball starts at one end and moves sequentially until it reaches the other e
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem involves passing a ball among n children arranged in a line. The ball starts at one end and moves sequentially until it reaches the other end, at which point it reverses direction. By thinking of the ball’s path as a “back-and-forth” motion, we can determine the final position after k passes by figuring out:

How many complete “trips” (from one end to the other) have been made.
The direction of the ball on the current (incomplete) trip.
# Approach
<!-- Describe your approach to solving the problem. -->
Setup the children:
We create a list children that represents each child by their index (0 to n-1).

Determine complete trips:

A complete trip from one end to the other consists of n-1 passes.
The expression (k // (n-1)) gives the number of complete trips.
Taking modulo 2, i.e., (k // (n-1)) % 2, tells us the direction of the ball:
0 indicates that the ball is moving from left to right.
1 indicates that the ball is moving from right to left.
Determine position in the current trip:

The remainder order = k % (n-1) gives the number of passes made in the current trip.
Depending on the direction:
If moving left to right, the ball will be at the child with index order.
If moving right to left, the ball will be at the child with index -order-1 (which is equivalent to n - 1 - order).

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
The algorithm involves creating a list of n children, which is an O(n) operation. The remaining arithmetic operations (division, modulo, and indexing) are all O(1).

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
The space used is O(n) due to the list of children.


# Code
```python []
class Solution(object):
    def numberOfChild(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: int
        """
        # child_with_ball = 0
        children = [i for i in range(n)]
        left_end_right_end = (k // (n-1)) % 2
        order = k % (n-1)
        if left_end_right_end == 0:
            child_with_ball = children[order]
        else:
            child_with_ball = children[-order-1]
        return child_with_ball
```
['Python']