void minimumBribes(vector<int> q)
{
int p1=1,p2=2,p3=3;
int total=0;
for(int i=0;i<q.size();i++)
{
int v=q[i];
if(v==p1)
{
p1=p2;
p2=p3++;
}
else if(v==p2)
{
total++;
p2=p3++;
}
else if(v==p3)
{
total+=2;
p3++;
}
else {
cout<<"Too chaotic"<<endl;
return;
}
}
cout<<total<<endl;
}
'코딩테스트 > HackerRank' 카테고리의 다른 글
[HackerRank] The Bomberman Game (0) | 2024.11.19 |
---|