case 1: L+R=N+1
arrange Nth bloack at L position and from N-1 to N-L on its left in
decreasing order.
N-L-1 to 1
on its right in decreasing order.
eg 3 4 5 6 2 1
for n=6
l=4
r=3
L+R<N+1
proceed as above
then place the remaining block between any two blocks.As the remaining
block will be shorter
than any all those that have already been placed they will never be
visible.
eg;
n=6
l=2
r=2
1) 5 6 4
place the remaining in between any two.
2) 5 3 2 1 6 4
here 3 2 1 will always be hidden
Ankit
On Oct 6, 4:04 pm, snehal jain <[email protected]> wrote:
> You are given N blocks of height 1…N. In how many ways can you arrange
> these blocks in a row such that when viewed from left you see only L
> blocks (rest are hidden by taller blocks) and when seen from right you
> see only R blocks?
>
> Examples:
> 1)For N=3, L=2, R=1 there is only one arrangement {2, 1, 3}.
> 2)For N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.