A and C are valid...
Just insert the elements into the stack as per given order...here order is given 1,2,3,4,5...
So if input contains any order which doesn't follow this is invalid...
For D..
insert 1,2,3 into the stack now top symbol is similar to the input symbol just pop it...
After popping 3 top of the stack is 2 not matched with remaining first input symbol...
So insert 4 into stack..Now matched pop it...
Same way insert 5 and pop it...
Now the I input symbol is 1 but top of the stack is 2...so this sequence is not followed
For B...
1,2,3 ,4,5 we need to insert but our stack size is 3 so not possible...
For A..
Push 1,2,3 now top matches so pop 3,2,1...
Push 4,5 top matches with input so pop 5,4
For C..
push 1,2,3, top match with input 3 so pop it...
Now push 4 , top matches with input so pop 4
Now push 5, top matches with input so pop 5,2,1