Question: we are given N blocks of height 1…N. In how many ways can we arrange these blocks in a row such that when viewed from left we can see only L blocks (rest are hidden by taller blocks) and when seen from right we see only R blocks? for N=3, L=2, R=2 there are two ways 1, 3, 2 and 2, 3, 1.

Solution: Consider the box with height 1. We can place it in the following ways:
1) leftmost position: It can be seen from left only (1 way to place)
2) rightmost position: It can be seen from right only (1 way to place)
3) Somewhere in between: Cannot be seen from either side as taller blocks will occupy both left and right side (N-2 ways to place)

After placing box with height 1, we again have the same subproblem while keeping box with height 2....and so on. This gives us the following recurrence relation:

countWays(N,L,R) = countWays(N-1,L-1,R) + countWays(N-1,L,R-1) + (N-2)*(countWays(N-1,L,R)