beats 100% simple solution
IntuitionPeople before and at index k will buy up to tickets[k] tickets.
People after index k will buy up to tickets[k] - 1 tickets, since they stop when k fini
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
People before and at index k will buy up to tickets[k] tickets.
People after index k will buy up to tickets[k] - 1 tickets, since they stop when k finishes.
# Approach
<!-- Describe your approach to solving the problem. -->
Iterate through the entire array (size n).
For each index i:
If i ≤ k: The person buys up to min(tickets[i], tickets[k]) tickets.
If i > k: The person buys up to min(tickets[i], tickets[k] - 1) tickets (since they don't get another turn after k finishes).
Sum up the tickets bought by all individuals to determine the total time taken.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
o(1)
![e0740cd9-706d-43ec-9419-32f91ebcda69_1719888937.7864256.png](https://assets.leetcode.com/users/images/ef480fc4-2f1d-4b34-a951-895d029a52cb_1740922707.9890285.png)

# Code
```cpp []
class Solution {
public:
    int timeRequiredToBuy(vector<int>& tickets, int k) {
        int n= size(tickets);
        
        int count = 0;
        for(int i=0;i<n;i++){
            if(i<=k){
                count+=min(tickets[i],tickets[k]);
            }
            else{
                count+=min(tickets[i],tickets[k]-1);
            }
        }
        return count;
    }
};
```
['C++']