0 ms java solution
suppose the given array is [2,3,7,5,1,2,7] and k is pointing to element = 5.\nwe need to find that each element is reduced how many times till we get 0 at the i
suppose the given array is [2,3,7,5,1,2,7] and k is pointing to element = 5.\nwe need to find that each element is reduced how many times till we get 0 at the index 3. The element before 5 will be reduced by = **minimum of (value of ith element, value of kth element)**\n the element before 5 are [2,3,7,5] and these will be reduced to [0,0,2,0] when the kth guy get ticket \n \n![image](https://assets.leetcode.com/users/images/bfea9c2c-94db-4fa0-8e6b-f20bf067424a_1654226809.5009036.png)\n\nnow element after 5 are [1,2,7] here we have a case, the element 1,2 will be completly reduce to 0 but the element greater than k will reduce to 1 lesser than the kth element (shown below ) because the kth element guy got the ticket and we don\'t need to worry about the leftover.\n\n![image](https://assets.leetcode.com/users/images/c826088c-eaf7-4d83-9543-a55494e2c89c_1654226960.949127.png)\n\n**please upvote my solution if u like it \u2764\uFE0F** \n```\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n        int count = 0;\n        for(int i = 0 ; i < tickets.length; ++i){\n            if(i <=k){\n                count += Math.min(tickets[i], tickets[k]);\n            }\n            else\n                count += Math.min(tickets[i], tickets[k] - 1);\n        }\n        return count;\n    }\n}\n```
['Java']