100% Runtime ✅💯, O(n) Time Complexity, O(1) Space Complexity ⚡️🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nThere will be as many rounds as the number of tickets kth person wants. The last round 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThere will be as many rounds as the number of tickets kth person wants. The last round will terminate at the kth person and thus the people after the kth one are visited one lesser time. \nThe Person who wants tickets lesser than that of kth person will just be in the rounds as many times he wants the tickets. Others will be as many times kth element will want. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet the number of tickets kth person wants be T.\nFor the people before kth person, if he wants more than T tickets, he gets T tickets until kth person gets T tickets. And if he wants less than T tickets, his want will be fulfilled earlier and he will participate the number of times as the number of tickets he wants.\n\nFor the people after kth person, it all will be applied with T-1 tickets as one lesser round will be carried out on them.\n\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: As we have just introduced ans. So, SC is O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int ans = 0;\n        for(int i=0; i<tickets.size(); i++){\n            if(i<=k) ans += min(tickets[i], tickets[k]);\n            else ans += min(tickets[i], tickets[k]-1);\n        }\n        return ans;\n    }\n};\n```
['C++']