Beats 100%✅✅||Super Easy🔥 Approach with explanation✅🔥
This question practically deals with to exhaust the linear possibilities till the kth ind. so,we check the values which are in corresponding to the kth value:\n
**This question practically deals with to exhaust the linear possibilities till the kth ind. so,we check the values which are in corresponding to the kth value:**\n\n**there are 3 poss:**\n\n**1.```i<=k```:\nwhen this arises we will be checking whether the element is lower \n```if Yes``` exhaust it till the end.\n```if No``` exhaust it till the kth val (as gien in the question).**\n\n**2.```i>k```:\nwhen this occurs,we will basically check if the element is lower or not.\n```if yes```then we will exhaust it till the end.\n```if No```then we will exhaust it til kth element-1. beacuse when we reach the kth element linearly we will stop right there and will not move further than that.**\n\n**so,this was the tricky part here.**\n\n**ex.\n1.{1,1,1,2},k=3:\nthis will become{0,0,0,1}->{0,0,0,0} total time was ```5```.**\n\n**2.{1,1,1,2},k=2:\nthis will become {0,0,0,2}-> and we got our answer in ```3 sec``` so why move further so we add 0 for the next columns than k which is nothing but ```kth element-1```**\n# Code\n``` Java []\nclass Solution {\n    public int timeRequiredToBuy(int[] tickets, int k) {\n        int result=0;\n        for(int i=0;i<tickets.length;i++){\n            if(tickets[i]<tickets[k]) result+=tickets[i];\n            else if(i<=k&&tickets[i]>=tickets[k]) result+=(tickets[k]);\n            else result+=tickets[k]-1;\n        }\n        return result;\n    }\n}\n```\n``` Python3 []\nclass Solution:\n    def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:\n        result = 0\n        for i in range(len(tickets)):\n            if tickets[i] < tickets[k]:\n                result += tickets[i]\n            elif i <= k and tickets[i] >= tickets[k]:\n                result += tickets[k]\n            else:\n                result += tickets[k] - 1\n        return result\n```\n``` C++ []\nclass Solution {\npublic:\n    int timeRequiredToBuy(vector<int>& tickets, int k) {\n        int result = 0;\n        for (int i = 0; i < tickets.size(); i++) {\n            if (tickets[i] < tickets[k]) {\n                result += tickets[i];\n            } else if (i <= k && tickets[i] >= tickets[k]) {\n                result += tickets[k];\n            } else {\n                result += tickets[k] - 1;\n            }\n        }\n        return result;\n    }\n};\n```\n``` JavaScript []\nfunction timeRequiredToBuy(tickets, k) {\n    let result = 0;\n    for (let i = 0; i < tickets.length; i++) {\n        if (tickets[i] < tickets[k]) {\n            result += tickets[i];\n        } else if (i <= k && tickets[i] >= tickets[k]) {\n            result += tickets[k];\n        } else {\n            result += tickets[k] - 1;\n        }\n    }\n    return result;\n}\n```
['Array', 'Simulation', 'C++', 'Java', 'Python3', 'JavaScript']