What question asked to do :- If any stack is empty then give the condition by which we can show "Error" if any pop operation appiled on a empty stack.
1) Given Q stacks of size P/Q, and it start from 0.
2) By giving stack 0 stores elements from 0 to Q-1 and so on (these no.'s are element's position in array S), they have actually given you the size of each stack i.e. P/Q = Q.
3) Now if a stack 0 is empty then it means top0 == -1, or it can be said top0 == 0*(P/Q) - 1,
Similary for top1 == Q-1
=> top1 == 1*(P/Q) - 1
=> top1 == Q - 1 ( P/Q = Q).
Now generalize it
Top i == i (P/Q) - 1