Google Residency Program 电面

11.11 两轮电话面试,现在还没收到结果。每轮45分钟,上来直接coding没有任何BQ。 ;_;

第一轮:

大意:

In a unbounded 2D grid, you have a list of people(represented by points) and a list of bikes (represented by points as well).

Everyone want to get a bike that’s closest to him/her, butthere are situations when two people’s closest(Hamilton distance) bike is thesame. In this situation, the person further from the bike will have to choosenext unoccupied bike etc.

Basd on this rule, find a person-bike mapping that representswhich person will get which bike?

楼主一开始有点紧张头脑一热说了个Bi-BFS感觉有点凉 :/…

后来慢慢写优化的算法,大概是先计算所有人对所有自行车的距离,然后放到MinHeap里。每次pop一个globally最少距离,输出人-自行车的mapping,然后删除所有有关这个自行车的距离record。直到结束。

不知道是不是有更好的方法。

第二轮:

输入在二位平面上的一组点,输出两个点以至于两点连线可以使两边剩余点的数量一致。

这题在想的前几分钟想到一个有趣的解法,大致是随意选择一个点作为(0,0)然后根据此点把剩下所有点转化成极坐标,然后简单的取degree的median就可以了。

用極坐標取median 會有錯吧。 如果總共六個點,其中一個點剛好在(0, 0),其他的點分別為 30, 60, 120, 255, 275 (度)。你的median 是120,你把(0, 0)跟120度的點連起來會發現點都在線的右側。

你说的对,应该再把一半degree旋转180度再找median,这样大概就能保证对了