登录
  • #美国面经
  • #码农类general
  • #面试经验
  • #palantir

Palantir Online Coding Test

weiqitoby600
3843
6
好久没有在地里发帖子了。。。

这个Test本来是该这周一提交的,后来推迟了五天,今天下午抽时间把Palantir他家的online做了。

忘记是怎么投的简历了,好像是通过LinkedIn投的。隔了一段时间,hr就联系我了,说要给我一个Online Test。于是我就在网上找面经啊。。。版主有个面经帖子,里面对Palantir和面试有简单的介绍。看版主问题答得那么好最后还是悲剧了,而且他也说过这是个面试难度相当高的公司。今天**就是抱着试一试的态度。

下面是题目, 很长,但是晚上有面经(career cup等等), 但是有所改动,大家可以搜出来答案。我也把答案在后面贴出来。由于最后一点疏忽,让输出的部分除了一些错误,太粗心了。

题目:

[backcolor=rgb(242, 242, 242)]A group of farmers has some elevation data, and we’re going to help them understand how rainfall flows over their farmland. [/backcolor]

[backcolor=rgb(242, 242, 242)]We’ll represent the land as a two-dimensional array of altitudes and use the following model, based on the idea that water flows downhill: [/backcolor]

[backcolor=rgb(242, 242, 242)]If a cell’s four neighboring cells all have higher altitudes, we call this cell a sink; water collects in sinks. [/backcolor]

[backcolor=rgb(242, 242, 242)]Otherwise, water will flow to the neighboring cell with the lowest altitude. If a cell is not a sink, you may assume it has a unique lowest neighbor and that this neighbor will be lower than the cell. [/backcolor]

[backcolor=rgb(242, 242, 242)]Cells that drain into the same sink – directly or indirectly – are said to be part of the same basin. [/backcolor]

[backcolor=rgb(242, 242, 242)]Your challenge is to partition the map into basins. In particular, given a map of elevations, your code should partition the map into basins and output the sizes of the basins, in descending order. [/backcolor]

[backcolor=rgb(242, 242, 242)]Assume the elevation maps are square. Input will begin with a line with one integer, S, the height (and width) of the map. The next S lines will each contain a row of the map, each with S integers – the elevations of the S cell

本帖隐藏的内容需要积分高于 188 才可浏览,点击前往一亩三分地论坛阅读

[/backcolor]


[backcolor=rgb(242, 242, 242)]Output: [/backcolor]

[backcolor=rgb(242, 242, 242)]7 5 4 [/backcolor]

[backcolor=rgb(242, 242, 242)]The basins, labeled with A’s, B’s, and C’s, are: [/backcolor]

[backcolor=rgb(242, 242, 242)]A A B B [/backcolor]

[backcolor=rgb(242, 242, 242)]A B B B [/backcolor]

[backcolor=rgb(242, 242, 242)]A B B C [/backcolor]

[backcolor=rgb(242, 242, 242)]A C C C[/backcolor]

本身就是抱着打酱油的心态去的,要是能给下一面,算是走了狗屎运了~ 希望大家能找到理想的工作offer。

补充内容 (2014-7-3 06:03):

这里定义的neighbor是一个cell周围八个方向的cell(不能越界)
6条回复
热度排序

发表回复