Most Optimal || Easy Math Simulation || Java solution
Code\n\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n        int time = 0, person = tickets[k];\n        int size = tickets.lengt
# Code\n```\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n        int time = 0, person = tickets[k];\n        int size = tickets.length;\n\n        for (int i = 0; i < size; i++) {\n            if (person <= tickets[i]) {\n                if (i <= k) {\n                    time += person;\n                } else {\n                    time += person - 1;\n                }\n            } else {\n                time += tickets[i];\n            }\n        }\n\n        return time;\n    }\n}\n```
['Array', 'Simulation', 'Java']