avatar
问个google面试题# JobHunting - 待字闺中
B*1
1
careercup上面看的
Partition a set of numbers into two such that difference between their sum
is minimum, and both sets have equal number of elements.
For example: {1, 4, 9, 16} is partitioned as {1,16} and {4,9} with diff = 17
-13=4.
Does greedy work here? First sorting, and then picking smallest and largest
to fall in set 1, and picking 2nd smallest and 2nd largest to fall in set 2.
I was asked to prove which I failed :(
avatar
g*i
2
partition problem变种,应该可以用subset problem的dp solution来做,wiki上说的.
greedy方法的approximation factor是4/3,很接近了.
楼主我觉得你老是钻研这种难题没啥必要,面试这种题目出现的概率极低,出了面试官也
会引导你的.
avatar
B*1
3
没有研究,careercup上的google的怎么都这么难。
avatar
y*g
4
careercup 估计是假题目吧
我觉得glassdoor好的多,

【在 B*******1 的大作中提到】
: 没有研究,careercup上的google的怎么都这么难。
avatar
B*1
5
是啊? 而且看了这几个我贴的这么难的都是google india的。
avatar
D*e
6
有人跟我说,随机置换两边的数(只要让结果变好就换)是最快的
avatar
c*p
7
greedy,容易达到local optimal.

【在 D*******e 的大作中提到】
: 有人跟我说,随机置换两边的数(只要让结果变好就换)是最快的
avatar
i*d
8
这应该是一个dp题。
等价于 在数组中找出 len/2个数,使得和在不大于 sum/2时,最大化.
avatar
c*x
9
必然是假的
子集和(NPC) => 二等分 => 二等分且两边元素个数相等 => minimum difference is 0
in this problem

17
largest
2.

【在 B*******1 的大作中提到】
: careercup上面看的
: Partition a set of numbers into two such that difference between their sum
: is minimum, and both sets have equal number of elements.
: For example: {1, 4, 9, 16} is partitioned as {1,16} and {4,9} with diff = 17
: -13=4.
: Does greedy work here? First sorting, and then picking smallest and largest
: to fall in set 1, and picking 2nd smallest and 2nd largest to fall in set 2.
: I was asked to prove which I failed :(

avatar
f*4
10
Genetic algorithm 就干这个事情的

【在 D*******e 的大作中提到】
: 有人跟我说,随机置换两边的数(只要让结果变好就换)是最快的
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。