JAVA Solution, Faster than 100% of all submissions O(n)
\n\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n      int output = 0;\n      int n = tickets.length;\n      for  (int i = 0;i<n;
```\n\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n      int output = 0;\n      int n = tickets.length;\n      for  (int i = 0;i<n;i++){\n          if(tickets[i] < tickets[k]){\n              output += tickets[i];\n          }else{\n                if(i <= k){\n                  output += tickets[k];\n              }else { \n                  output += tickets[k] - 1;\n              } \n          }\n\n      }\n      return output;\n    }\n}\n```\n```
[]