Time Complexity : O(N) Space Complexity : O(1) [Diagrammatic Explanation]
Intuition & Approach\n\n\n\n\n# Complexity\n- Time complexity: O( size of array tickets[] )\n\n- Space complexity: O( 1 ) Constant\n\n\n# Code\n\nclass Solution
# Intuition & Approach\n![Screenshot from 2024-04-09 12-36-58.png](https://assets.leetcode.com/users/images/dfef91fe-bdb7-45f2-8648-9bcf57f51f60_1712652497.88228.png)\n\n\n\n# Complexity\n- Time complexity: O( size of array tickets[] )\n\n- Space complexity: O( 1 ) Constant\n\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int res = 0;\n        for(int i = 0; i < tickets.size(); i ++){\n            if(tickets[i]<tickets[k]) res+=tickets[i];\n            else res+= (i<=k)?tickets[k]:tickets[k]-1;\n        }\n        return res;\n    }\n};\n\n```
['C++']