Easy solution with explanation
If you like it, please upvote\n\n# Code\n\n/**\n * @param {number[]} tickets\n * @param {number} k\n * @return {number}\n */\nvar timeRequiredToBuy = function(t
If you like it, please upvote\n\n# Code\n```\n/**\n * @param {number[]} tickets\n * @param {number} k\n * @return {number}\n */\nvar timeRequiredToBuy = function(tickets, k) {\n    // current index\n    let i = 0;\n    // number of steps\n    let steps = 0;\n\n    // while tickets[k] > 0\n    while (tickets[k]) {\n        // we do not need to reset i because it is easier to calculate index in the array\n        const index = i % tickets.length;\n        if (tickets[index]) {\n            // if element is not 0 then decrement the value and increment the number of steps\n            tickets[index]--;\n            steps++;\n        }\n        // every time move to next element\n        i++;\n    }\n\n    return steps;\n};\n```
['JavaScript']