PROBLEM SETTER -
SOLUTION IN SHORT -
There are no techniques or optimizations. Do as directed!!!
There is a while loop which has a condition of breaking to be when input numer is 0. You can maintain a variable i denoting the current position of crane. You also have stored the stack sizes in an array a. For drop command, check if a[i]+1 is greater than h, if not, increment a[i]. For pick command, check if a[i] is positive, if yes, decrement a[i]. For moving left, do i-- and for moving right, do i++ and accordingly check if i > 1 (for moving left) and i < N (for moving right). Outside the while loop, after it has ended, output the array a.
TIME COMPLEXITY -
O(number of queries/operations)