Easy Solution Even Koko Understands When She Eats Banana | Binary Search
Intuition
The problem is asking for the minimum time, which is a signal to use binary search.
The key insight is realizing we should only mark an index at its l
# Intuition
1. The problem is asking for the minimum time, which is a signal to use binary search.
2. The key insight is realizing we should only mark an index at its last occurrence in the changeIndices array.
3. Before marking an index, we need to decrease its value to 0, which requires gathering "extra" moves.
4. Working backward from the time limit, if we can mark all indices by time T, we can definitely mark them by time T+1.
5. Remember that changeIndices is 1-indexed, so we need to subtract 1 when accessing the actual index in nums.

The binary search efficiently finds the earliest possible time by narrowing down the range.

# Approach
1. We use binary search to find the minimum time needed to mark all indices.
2. For each potential time we check (the helper function), we:

    - Track the last occurrence of each index in the changeIndices array up to the current second
    - Keep track of "extra" moves (when we don't mark an index) that can be used to decrease values
    - Process each second and only mark an index if it's the last time we see that index
We can only mark an index if we have enough "extra" moves to reduce its value to 0



The key strategy is to use extra moves to reduce values and then mark indices at their last occurrence in the changeIndices array.

# Complexity
- Time complexity:$$O(n*logm)$$

- Space complexity:$$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def earliestSecondToMarkIndices(self, nums: List[int], changeIndices: List[int]) -> int:
        def helper(second):
            last = {changeIndices[i] : i for i in range(second)}
            k = nums.copy()
            curr, marked = 0,  [0] * len(nums)
            extra = 0
            for i in range(second):
                idx = changeIndices[i] - 1
                if last[changeIndices[i]] == i:
                    if extra >= k[idx]:
                        extra -= k[idx]
                        marked[idx] = 1
                        curr += 1
                        k[idx] = 0
                    else:
                        return False
                else:
                    extra += 1
            return curr == len(nums)

        left = 0
        right = len(changeIndices)
        while left < right:
            mid = (left + right) // 2
            if helper(mid):
                right = mid
            else:
                left = mid + 1
        return left if helper(left) else -1
```
['Binary Search', 'Python3']