👏Beats 100.00% of users with Java || ✅Simple & Easy Well Explained Solution 🔥💥
Intuition\nCount the time min of the tickets[i] and tickets[k] except i and k is same and count ignore after k that is no need to count time after tickets[k] is
# Intuition\nCount the time min of the tickets[i] and tickets[k] except i and k is same and count ignore after k that is no need to count time after tickets[k] is getting 0.\n\n# I Think This Can Help You(For Proof Click on the Image)\n[![Screenshot 2024-02-24 232407.png](https://assets.leetcode.com/users/images/f2df15e3-7b31-48b6-8d2a-60d275c28c2c_1712730584.57641.png)](https://leetcode.com/problems/time-needed-to-buy-tickets/submissions/1228295358/?envType=daily-question&envId=2024-04-09)\n\n# Approach\n1. Initilize time and ignore counter variable as 0.\n    ```\n    int time=0;\n    int ignore=0;\n    ```\n2. Iterate the loop and count time min of the tickets[i] and tickets[k] except when i and k is equal.\n3. Count ignore after k when tickets[k] is equal to 0 and tickets[i] is not equal to 0.\n    ```\n    for(int i=0;i<tickets.length;i++){\n        if(i!=k){\n            time = time + Math.min(tickets[k],tickets[i]);\n        }\n        if(tickets[i]>=tickets[k] && k<i){\n            ignore++;\n        }\n    }\n    ```\n4. Icrease time by tickets[k].\n    ```\n    time+=tickets[k];\n    ```\n5. return time - ignore, beacuse we need to remove after k that is not having 0 in the time.\n    ```\n    return time - ignore;\n    ```\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n         int time=0;\n        int ignore=0;\n        for(int i=0;i<tickets.length;i++){\n            if(i!=k){\n                time = time + Math.min(tickets[k],tickets[i]);\n            }\n            if(tickets[i]>=tickets[k] && k<i){\n                ignore++;\n            }\n        }\n        time+=tickets[k];\n        return time - ignore;\n    }\n}\n```\n![_6c41b458-05b9-4888-a584-dcee91a72877.jpeg](https://assets.leetcode.com/users/images/b93c4a2b-05c2-4ca3-a56a-33fff385da29_1712731032.520468.jpeg)\n
['Array', 'Queue', 'Simulation', 'Java']