100% Beats || Easy C++ ||  Queue || O(N)
Intuition\n1st push all the element into queue if kth element is greater than 1.\npush the element if after decrement it is still greate than 0.\n\n# Approach\n
# Intuition\n1st push all the element into queue if kth element is greater than 1.\npush the element if after decrement it is still greate than 0.\n\n# Approach\ninitilly change the sign of the kth element so that you recognize it in future. than simple queue approach.\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int i = 0, n = tickets.size(), sec = 0;\n        queue<int> que;\n        tickets[k] = -tickets[k];\n        while(tickets[k] && i < n){\n            if(i == k) que.push(++tickets[i]); \n            else if(--tickets[i]) que.push(tickets[i]);\n            i++; sec++;\n        }\n        while(!que.empty() && tickets[k]){\n           auto top =  que.front();\n           sec++; que.pop();\n           if(top - 1 == 0 ) continue;\n           top < 0 ? que.push(++tickets[k]): que.push(--top);\n        }\n        return sec;\n    }\n};\n```
['Queue', 'C++']