ADAQUEUE - Ada and Queue
Ada the Ladybug has many things to do. She puts them into her queue. Anyway she is very indecisive, so sometime she uses the top, sometime the back and sometime she decides to reverses it.
The first line consists of 1 ≤ Q ≤ 106, number of queries. Each of them contains one of following commands
back - Print number from back and then erase it
front - Print number from front and then erase it
reverse - Reverses all elements in queue
push_back N - Add element N to back
toFront N - Put element N to front
All numbers will be 0 ≤ N ≤ 100
For each back/front query print appropriate number.
If you would get this type of query and the queue would be empty, print "No job for Ada?" instead.
15 toFront 93 front back reverse back reverse toFront 80 push_back 53 push_back 50 front front reverse push_back 66 reverse front
93 No job for Ada? No job for Ada? 80 53 66
Last edit: 2019-10-02 21:20:19
drives me crazy , but solved eventually , no need for reversing all the queue , just using a flag to determine if that is traversed or not , good luckLast edit: 2019-09-14 23:11:15
Reverse input doesn't only reverse the elements, it should reverse all operations, be careful because that costed me a few WAs
use deque with flag variable !
IF you are getting wrong with linked list try using the deque
Last edit: 2018-05-31 21:41:38
Used Double Linked List...0.16s...Lot of Typing...
I'm getting WA in python, dont know y. I cant find a test case which breaks my code.Last edit: 2017-11-09 21:34:27
Easy problem. AC in one go. Just remember you don`t need to reverse your queue actually.