Java - Easy Solution O(n)
Time Needed to Buy Tickets\n\nSimple and crisp Solution - \n\nInput: tickets = [2,3,2], k = 2\nOutput: 6\nExplanation: \n- In the first pass, everyone in the li
**Time Needed to Buy Tickets**\n\nSimple and crisp Solution - \n\n**Input:** tickets = [2,3,2], k = 2\n**Output:** 6\n**Explanation:** \n- In the first pass, everyone in the line buys a ticket and the line becomes [1, 2, 1].\n- In the second pass, everyone in the line buys a ticket and the line becomes [0, 1, 0].\nThe person at position 2 has successfully bought 2 tickets and it took 3 + 3 = 6 seconds.\n\n```\npublic int timeRequiredToBuy(int[] tickets, int k) {\n        int timeTaken = 0;\n        while(tickets[k] > 0) {\n        \tfor(int i = 0; i < tickets.length; i++) {\n        \t\tif(tickets[i] > 0) {\n        \t\t\ttickets[i]--;\n        \t\t\ttimeTaken++;\n        \t\t}\n                if(tickets[k] == 0)  break;\n        \t}\n        }\n        return timeTaken;\n    }\n```\n\t\nTime Complexity - **O(n*k)**\n\n\t\n```\n\tpublic int timeRequiredToBuy(int[] tickets, int k) {\n\t      int timeTaken = 0;\n          for(int i = 0; i < tickets.length; i++){\n                if(tickets[i] <= tickets[k]){\n                     timeTaken += tickets[i];\n                }\n                else  timeTaken += tickets[k];\n                if(i > k && tickets[i] >= tickets[k])  timeTaken--;\n          }\n          return timeTaken;\n    }\n```\t\n\t\nTime Complexity - **O(n)**\n\nCredit - @yadavharsha50
['Java']