✅100% || Easy Solution🔥With explanation🔥||Beginner Friendly
Intuition\nTo solve this problem, we need to calculate the time required to buy tickets given a specific index \'k\'. The idea is to iterate through the tickets
# Intuition\n**To solve this problem, we need to calculate the time required to buy tickets given a specific index \'**k**\'. The idea is to iterate through the tickets array and sum up the values, then calculate the number of elements bigger than the **k-th** element that occur after it, as these elements will not decrease in the last round. Subtracting this count from the total sum gives us the final answer.**\n\n# Approach\n1.Initialize variables \'**sum\'** to store the sum of all elements in the tickets array and \'**bigger\'** to count the number of elements bigger than the k-th element that occur after it.\n2.Iterate through the tickets array and update \'sum\' and \'**bigger\'** accordingly.\n3.Calculate the time required to buy tickets by summing up the minimum of temp and \'**tickets[i]**\' for each element in the array.\n4.Subtract the count of \'**bigger**\' from the calculated answer to get the final result.\nReturn the final answer.\n\n# Complexity\n#### - Time complexity:\n**O(n)**, where n is the size of the tickets array. We iterate through the array once to calculate the sum and count the number of elements bigger than the k-th element.\n\n#### - Space complexity:\n**O(1)**, as we use only a constant amount of extra space for storing variables.\n\n# Code\n```\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int sum = 0,bigger = 0;//bigger: Number of bigger elements than kth element which are coming after it.\n        //the bigger elements after kth element will not get decreament in the last round as the kth element becomes 0.\n        for(int i = 0;i < tickets.size();i++)\n        {\n            sum += tickets[i];\n\n            if(i > k && (tickets[i] >= tickets[k]))\n            {\n               bigger++;\n            }\n        }\n        \n        int temp = tickets[k],ans = 0;\n\n        for(int i = 0;i < tickets.size();i++)\n        {\n            ans += min(temp,tickets[i]);//whichever is small will be added\n        }\n        \n        return (ans - bigger);//decreament number of bigger elements from the ans\n        \n    }\n};\n```
['Array', 'Greedy', 'Counting', 'C++']