long waitingTime(vector<int> tickets, int p) {
// bool flag indicates whether it's Jesse or not
queue<pair<int, bool> > aQueue;
for(int i = 0; i < tickets.size(); i++) {
aQueue.push(make_pair(tickets[i], i == p));
}
long long nTime = 1;
while(!aQueue.empty()) {
pair<int, bool> aItem = aQueue.front();
aQueue.pop();
nTime++;
if(aItem.first == 1 && aItem.second == true)
break;
else if(aItem.first > 1) {
aQueue.push(make_pair(aItem.first-1, aItem.second));
}
}
return nTime-1;
}
Ade Ihsan
0
Newbie Poster
Recommended Answers
Jump to PostWhy does this code look so much like https://stackoverflow.com/questions/43950000/hackerrank-buying-show-tickets-optimization which is a post from about 2013?
It appears this is a online screening test of a company and is just one part of a longer app I see at
All 2 Replies
rproffitt
2,565
"Nothing to see here."
Moderator
rproffitt
2,565
"Nothing to see here."
Moderator
ddanbe
commented:
Knowledge!
+15
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.