c++ || optimal approach || O(n)
image.png\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Comp
image.png\n![image.png](https://assets.leetcode.com/users/images/ddd9a133-27da-4978-9f31-45c62dacb45e_1712645136.286996.png)\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int ans=0;\n\n        for(int i=0 ; i<tickets.size() ; i++){\n            if(i<=k){\n                ans += min(tickets[i] , tickets[k]);\n            }\n            else{\n                ans += min(tickets[i] , tickets[k] - 1);\n            }\n        }   \n        return ans;\n    }\n};\n```
['C++']