由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一道google的题
相关主题
问一道算法题MySpace是不是衰落了?
现在面试可以用Java8吗?Bitonic search的问题
bloomberg电话面经fb 面经
question about prevailing wageamazon电话面试
一道微软题大家觉得resume和onsite的重要程度如何?
Google 面试题 一道问两道面试题
一个brain teaser题目A simple google interview question
请教一个DP的问题问个google面试题
相关话题的讨论汇总
话题: decreased话题: output话题: array话题: elements话题: sum
进入JobHunting版参与讨论
1 (共1页)
s****t
发帖数: 36
1
在careercup上面看的,题目看不是很懂,大家看看是问什么东西啊。
Given n elements, sort the elements. Here, only one operation is
permitted decreaseValue..
Note that you cannot swap the values.. output should be a sorted
list..
if input is 4 5 2 1 3
output is 3 3 3.. There can be many answers.. Give the optimum
solution with minimum cost. where as cost is the sum of decreased
amounts..
for this example, 4,5 are decreased by 1.. 2 is decreased by 2.. 1
is decreased by 1..
m*****g
发帖数: 226
2
只能想到n*n的解法
s*******s
发帖数: 46
3
4 5 2 1 3 -> 3 3 3 the sum of decreased value is 6
4 5 2 1 3 -> 4 3 2 1 the sum of decreased value is 5
get confused?
Do I misunderstand the question?
b***u
发帖数: 61
4

为啥少了两个数呢?2 和1去哪里了?

【在 s*******s 的大作中提到】
: 4 5 2 1 3 -> 3 3 3 the sum of decreased value is 6
: 4 5 2 1 3 -> 4 3 2 1 the sum of decreased value is 5
: get confused?
: Do I misunderstand the question?

B*****t
发帖数: 335
5
I think O(n^2) is already the optimal solution.

【在 m*****g 的大作中提到】
: 只能想到n*n的解法
m*****g
发帖数: 226
6
4 5 2 1 3 -> 3 3 3
你那个变成倒序了

【在 s*******s 的大作中提到】
: 4 5 2 1 3 -> 3 3 3 the sum of decreased value is 6
: 4 5 2 1 3 -> 4 3 2 1 the sum of decreased value is 5
: get confused?
: Do I misunderstand the question?

m*****g
发帖数: 226
7
and it is a brutal force one.

【在 B*****t 的大作中提到】
: I think O(n^2) is already the optimal solution.
B*****t
发帖数: 335
8
so could you please present your O(N^2) approach?

【在 m*****g 的大作中提到】
: and it is a brutal force one.
m*****g
发帖数: 226
9
input array array[1...n]
for int i from 1 to n
calculate the decreases needed if the output max is array[i]
that is it.

【在 B*****t 的大作中提到】
: so could you please present your O(N^2) approach?
B*****t
发帖数: 335
10
the problem is how to calculate the decreases needed if the output
max is array[i]

【在 m*****g 的大作中提到】
: input array array[1...n]
: for int i from 1 to n
: calculate the decreases needed if the output max is array[i]
: that is it.

相关主题
Google 面试题 一道MySpace是不是衰落了?
一个brain teaser题目Bitonic search的问题
请教一个DP的问题fb 面经
进入JobHunting版参与讨论
m*****g
发帖数: 226
11
input array 5 4 3 2 1
5: 5 (rest all reduced to none, so add them up as u visit them)
4: 4 4 (get the first diff, add the rest up)
3: 3 3 3
2: 2 2 2 2
1: 1 1 1 1 1
每个只要算一遍就行了吧,不至于真的要一个一个减吧

【在 B*****t 的大作中提到】
: the problem is how to calculate the decreases needed if the output
: max is array[i]

B*****t
发帖数: 335
12
what about 4 8 6 3 5 7 ?? how do you calculate min decreased
value?

【在 m*****g 的大作中提到】
: input array 5 4 3 2 1
: 5: 5 (rest all reduced to none, so add them up as u visit them)
: 4: 4 4 (get the first diff, add the rest up)
: 3: 3 3 3
: 2: 2 2 2 2
: 1: 1 1 1 1 1
: 每个只要算一遍就行了吧,不至于真的要一个一个减吧

m*****g
发帖数: 226
13
全都找一遍阿,不然干什么要O(n2)。都找一遍了看谁最小阿
4:4 4 (-3) 4 (-2) 0(-3) 4(-1) 4 (-3)

【在 B*****t 的大作中提到】
: what about 4 8 6 3 5 7 ?? how do you calculate min decreased
: value?

m*****g
发帖数: 226
14
又想了一下,这个方法行不通。
等高手了

【在 m*****g 的大作中提到】
: 全都找一遍阿,不然干什么要O(n2)。都找一遍了看谁最小阿
: 4:4 4 (-3) 4 (-2) 0(-3) 4(-1) 4 (-3)

B*****t
发帖数: 335
15
I think either you or me misunderstand the problem.
sort the elements does not need to make them all equal

【在 m*****g 的大作中提到】
: 全都找一遍阿,不然干什么要O(n2)。都找一遍了看谁最小阿
: 4:4 4 (-3) 4 (-2) 0(-3) 4(-1) 4 (-3)

m*****g
发帖数: 226
16
what is wrong is my solution. i think i get the problem right.

【在 B*****t 的大作中提到】
: I think either you or me misunderstand the problem.
: sort the elements does not need to make them all equal

K******g
发帖数: 1870
17
请问谁能把这个问题解释一遍?我看了大半天,不知所云。
h**k
发帖数: 3368
18
我的理解是,输入无序数组,不能交换数组位置,只能减少数组中的元素值;如果某个
元素减为零,则认为从数组中移走。输出一个排序的数组,要求减少量最小。
怀疑是NP-hard问题,可以用穷举法找到最优解;用greedy算法给出近似解。
DP似乎不行。
1 (共1页)
进入JobHunting版参与讨论
相关主题
问个google面试题一道微软题
问个电面题Google 面试题 一道
周五面capital one,可否麻烦大家看几道题一个brain teaser题目
FB coding challenge sample question请教一个DP的问题
问一道算法题MySpace是不是衰落了?
现在面试可以用Java8吗?Bitonic search的问题
bloomberg电话面经fb 面经
question about prevailing wageamazon电话面试
相关话题的讨论汇总
话题: decreased话题: output话题: array话题: elements话题: sum