easy code in c++
\n\n# Brute force\n\n# Code\n\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int count=0,i=0,n=tickets.size();\n 
\n\n# Brute force\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int count=0,i=0,n=tickets.size();\n        while(tickets[k]!=0) {\n            if(tickets[i]!=0) {\n                tickets[i]--;\n                count++;\n            }\n            i++;\n            i=i%n;\n        }\n        return count;\n    }\n};\n```\n# Optimized\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int count=0,n=tickets.size();\n        int kVal=tickets[k];\n        for(int i=0;i<n;i++) {\n            if(i<=k) {\n                count += min(tickets[i],kVal);\n            }\n            else {\n                count+= min(tickets[i],kVal-1);\n            }\n        }\n        return count;\n    }\n};\n```
['C++']