BRUTE(DEQUE) + OPTIMISED(IN ONE PASS)
1)BRUTE FORCE APPROACH -> \nA) SIMULATE THE GIVEN PROBLEM USING DEQUE DATA STRUCTURE  \nKEEP A COUNTER WHEN KTH ELEMENT BECOMES 0 THATS EASY :)\n\nTC -> O(K * A
1)BRUTE FORCE APPROACH -> \nA) SIMULATE THE GIVEN PROBLEM USING DEQUE DATA STRUCTURE  \nKEEP A COUNTER WHEN KTH ELEMENT BECOMES 0 THATS EASY :)\n\nTC -> O(K * ARR[K]) -> IN WORST CASE IF K IS LAST ELEMENT\nSC -> O(2*N) -> TAKEN A PAIR\n\nCODE -> \n```\n\t\tdeque<pair<int,int>>dq;\n        for(int i = 0;  i < tickets.size(); i++) {\n            dq.push_back({tickets[i] , i});\n        }\n        int ans = 0;\n        while(!dq.empty()) {\n            int val = dq.front().first;\n            int idx = dq.front().second;\n            val--;\n            ans++;\n            if(idx == k && val == 0) {\n                break;\n            }\n            if(val == 0) {\n                dq.pop_front();\n            } else {\n                dq.pop_front();\n                dq.push_back({val, idx});\n            }\n        }\n        return ans;\n```\n\nOPTIMISED APPROACH->\n\nTHINK WITH RESPECT TO K -> TAKE 2 CASES\n1) ELEMENTS BEFORE K -> WILL TAKE MIN(ARR[I] , ARR[K]) STEPS IN TOTAL\n2) ELEMENTS AFTER K  ->  WILL TAKE MIN(ARR[I] , ARR[K] - 1 STEPS) IN TOTAL\n3) YOUR ANS IS (1 + 2) -> \n\nCODE -> \n```\n\t int ans = 1;\n        int val = tickets[k];\n        for(int i = 0 ; i < tickets.size(); i++) {\n            if(i < k) {\n                //THE ELEMENTS THAT LIE BEFORE K\n                if(tickets[i]  < val) {\n                    ans += tickets[i];\n                } else {\n                    ans += val;\n                }\n            } else {\n                //THE ELEMENTS THAT LIE AFTER K\n                if(tickets[i] < val - 1) {\n                    ans += tickets[i];\n                } else {\n                    ans += (val - 1);\n                }   \n            }   \n        } \n        return ans;\n```\n\nTC -> O(N) SINGLE PASS\nSC -> O(1) :)\n\nTHANK YOU DO SHARE AND UPVOTE IF YOU LIKED THE APPROACH\n
['Queue']