✅C++ || 2 ways || Bruteforce->Optimal
Method-1 [Brute Force]\n\n\n\nn==t.size()\nT->O(tickets[k] * n) && S->(1)\n\n\tclass Solution {\n\tpublic:\n\t\tint timeRequiredToBuy(vector& t, int k) {\n\t\t\
# Method-1 [Brute Force]\n\n![image](https://assets.leetcode.com/users/images/c883d3c4-59d3-430e-a16d-5e1b6532e52b_1657263680.476677.png)\n\n**n==t.size()\nT->O(tickets[k] * n) && S->(1)**\n\n\tclass Solution {\n\tpublic:\n\t\tint timeRequiredToBuy(vector<int>& t, int k) {\n\t\t\tint time=0;\n\t\t\twhile(1){\n\t\t\t\tfor(int i=0;i<t.size();i++){\n\t\t\t\t\tif(t[i]>0){\n\t\t\t\t\t\tt[i]--;\n\t\t\t\t\t\ttime++;\n\t\t\t\t\t\tif(t[k]==0)return time;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\t};\n\t\n\t\n# Method-2 [Optimal solution]\t\n\t\n![image](https://assets.leetcode.com/users/images/98e24ff0-6f30-429b-8292-63a194bf3895_1657264759.6914196.png)\n\n**In one pass!\nT->O(n) && S->O(1)**\n\n\tclass Solution {\n\tpublic:\n\t\tint timeRequiredToBuy(vector<int>& t, int k) {\n\t\t\tint time=0;\n\t\t\tfor(int i=0;i<t.size();i++){\n\t\t\t\tif(t[i]<t[k])time+=t[i];\n\t\t\t\telse time+=t[k];\n\t\t\t\tif(i>k && t[i]>=t[k])time--;\n\t\t\t}\n\t\t\treturn time;\n\t\t}\n\t};
['C', 'C++']