Islamorada归来,奔些花花草草# gardening - 拈花惹草
r*g
1 楼
1,Given a n-ary tree. A random leaf node will be selected.Imagine that you
are now holding the tree with your hand from that node. All other nodes will
now fall under gravity. Write a function to perform this transformation.
n-ary tree又不是bst,这题什么意思,怎么也无法想象把一个节点提起来是什么感觉
2,Given two lists, each containing numbers, how would you find the
intersection of these two lists? What if these two lists are read from a
huge file that cannot fit in memory?
如果文件很大该怎么办,我能想到的是尝试一个number对应一位,但是如果memory实在
有限,number的range很大,那也没有办法。
3,Given 3 prime numbers and an integer k, find the kth number if all the
nos which are having these 3 prime numbers as their factors are arranged in
increasing order.
Eg. prime numbers - 2,3,5
The increasing sequence will be 2,3,4,5,6,8,9...
这个题我在careerup上看到两次了,都没看到好的解法,我能想到的是,当你走到2^l*
3^m*5^n时,下一个数一定是通过2^l*3^m*5^(n-1)之后的数变化得到,这样就抛弃了很
多数,假设紧接2^l*3^m*5^(n-1)的数是M,那么下一个数就在2^l*3^m*5^n和M*5之间,
这个范围有可能很大,挨个做质因数分解似乎不大对。似乎这个题只能尽量使amotized
时间尽量小?any link on this?
谢了
are now holding the tree with your hand from that node. All other nodes will
now fall under gravity. Write a function to perform this transformation.
n-ary tree又不是bst,这题什么意思,怎么也无法想象把一个节点提起来是什么感觉
2,Given two lists, each containing numbers, how would you find the
intersection of these two lists? What if these two lists are read from a
huge file that cannot fit in memory?
如果文件很大该怎么办,我能想到的是尝试一个number对应一位,但是如果memory实在
有限,number的range很大,那也没有办法。
3,Given 3 prime numbers and an integer k, find the kth number if all the
nos which are having these 3 prime numbers as their factors are arranged in
increasing order.
Eg. prime numbers - 2,3,5
The increasing sequence will be 2,3,4,5,6,8,9...
这个题我在careerup上看到两次了,都没看到好的解法,我能想到的是,当你走到2^l*
3^m*5^n时,下一个数一定是通过2^l*3^m*5^(n-1)之后的数变化得到,这样就抛弃了很
多数,假设紧接2^l*3^m*5^(n-1)的数是M,那么下一个数就在2^l*3^m*5^n和M*5之间,
这个范围有可能很大,挨个做质因数分解似乎不大对。似乎这个题只能尽量使amotized
时间尽量小?any link on this?
谢了