One Pass C++ || Easy to Understand  ⭐⭐
People infront of our target person will get all their tickets before our target man if they want tickets less than or equal to him. If they want more tickets t
People infront of our target person will get all their tickets before our target man if they want tickets less than or equal to him. If they want more tickets than him they will only get tickets equal to him till target man gets all his tickets.\n\nFor people behind target man, they will get all tickets if they want tickets strictly less than him. If they want more than him, they will get one less than tickets target man wants till he gets all his tickets.\n\'\'\'\n              \n    class Solution {\n    public:\n        int timeRequiredToBuy(vector<int>& tickets, int k) {\n            int n=tickets.size();\n            int time=tickets[k];\n            for(int i=0;i<tickets.size();i++){\n            //Elements infront of target\n                  //If they are smaller or equal to target value collect them whole \n                  //If they are greater collect target value\n            if(i<k){\n                if(tickets[i]<=tickets[k]){\n                    time+=tickets[i];\n                }\n                else{\n                    time+=tickets[k];\n                }\n            }\n            //Elements behind target\n                  //If they are smaller than target value collect them whole \n                  //If they are greater collect (target-1) value\n            else if(i>k){\n                if(tickets[i]<tickets[k]){\n                    time+=tickets[i];\n                }\n                else{\n                    time+=(tickets[k]-1);\n                }\n            }\n        }\n        return time;\n    }\n};\n\t\t\t        \n\t\t\t      \n\'\'\'
['C']