avatar
[Google] Arangement of blocks# JobHunting - 待字闺中
s*l
1
http://discuss.techinterview.org/default.asp?interview.11.79942
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? Example given N=3, L=2, R=1 there is only one arrangement {2, 1, 3}
while for N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}.
avatar
g*s
2
brute-force?

blocks
R
3}

【在 s*********l 的大作中提到】
: http://discuss.techinterview.org/default.asp?interview.11.79942
: 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? Example given N=3, L=2, R=1 there is only one arrangement {2, 1, 3}
: while for N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}.

avatar
Z*Z
3
Term:
13766
Web:
http://mitbbs.com/article1/JobHunting/31588989_3_0.html

blocks
}

【在 s*********l 的大作中提到】
: http://discuss.techinterview.org/default.asp?interview.11.79942
: 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? Example given N=3, L=2, R=1 there is only one arrangement {2, 1, 3}
: while for N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}.

avatar
s*l
4
我的基本想法是构造满足条件的binary max heap,然后按中序输出,有点cartesian
tree的意思.

blocks
}

【在 s*********l 的大作中提到】
: http://discuss.techinterview.org/default.asp?interview.11.79942
: 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? Example given N=3, L=2, R=1 there is only one arrangement {2, 1, 3}
: while for N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}.

avatar
g*s
5
sorry, what's the connection to max heap?

【在 s*********l 的大作中提到】
: 我的基本想法是构造满足条件的binary max heap,然后按中序输出,有点cartesian
: tree的意思.
:
: blocks
: }

avatar
s*l
6
seems the number of nodes on the left-most path is L
and the number of nodes on the right-most path is R
Examples:
(1) given N=3, L=2, R=1 there is only one arrangement {2, 1, 3}
{2,1,3} corresponds to the cartesian tree
3
/
2
\
1
Left-most path: 3->2
Right-most path: 3
(2) while for N=3, L=2, R=2 there are two ways {1, 3, 2} and {2, 3, 1}.
{1,3,2} corresponds to the cartesian tree
3
/ \
1 2
Left-most path: 3->1
Right-most path: 3->2
{2,3,1} corresponds to the cartesian tree
3
/ \
2 1
Left-most path: 3->2
Right-most path: 3->1

【在 g*********s 的大作中提到】
: sorry, what's the connection to max heap?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。