#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void findTimeToBuyTicket(vector<int> tickets ,int k){
int timetaken=0;
while(tickets[k]!=0){
for (int i =0;i<tickets.size();i++){
if(tickets[i] ==0){
continue;
}
tickets[i]--;
timetaken++;
if(i==k){
break;
}
}
}
cout<<"Time taken of kth person is: " <<timetaken<<endl;
}
int main() {
//Write your C++ code here
vector<int> tickets ={5,1,1,1};
findTimeToBuyTicket(tickets,2);
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter