Redian新闻
>
文章作者地址署名问题
avatar
文章作者地址署名问题# Biology - 生物学
K*k
1
面经题:
Stock history data int stock[n], find the best sell and buy time.
化归题:
数组中,一个元素(第一个元素除外)减去它左边的某一个元素可以得到一个差值,求所
有这些差值的最大值。不是最大值减去最小值,比如:
{3, 4, 2, 7, 16, 1, 5, 11, 9}, 答案是16 - 2 = 14, 不是 16 - 1 = 15
avatar
p*5
2
TSC, 485, RD Mid January, still waiting.
avatar
k*n
3
有一片专业领域不错的文章马上要投了,老板说把我(我是一作)的地址加一个他在国
内大学地址,他在这个大学特聘兼职教授, 并且把国内地址改为第一地址,这边的地
址改为第二地址。他说主要是特聘要交差。请问这样对以后找工作没有什么影响吧。不
知道呀,求指点。
avatar
q*x
4
just do max.

【在 K*****k 的大作中提到】
: 面经题:
: Stock history data int stock[n], find the best sell and buy time.
: 化归题:
: 数组中,一个元素(第一个元素除外)减去它左边的某一个元素可以得到一个差值,求所
: 有这些差值的最大值。不是最大值减去最小值,比如:
: {3, 4, 2, 7, 16, 1, 5, 11, 9}, 答案是16 - 2 = 14, 不是 16 - 1 = 15

avatar
c*o
5
同情中!
我是 TSC 的二月中的,一直没有消息,打了电话,要我耐心的等,要6个月!
co-bless!
avatar
f*g
6
no influence, but if you insist that your address is the first one, then it
will influence.
avatar
b*y
7
如果是long position的话,两个题目是一样的
cracking google interview上面有解答
扫描一遍,maintain current min value以及maintain最大差值

【在 K*****k 的大作中提到】
: 面经题:
: Stock history data int stock[n], find the best sell and buy time.
: 化归题:
: 数组中,一个元素(第一个元素除外)减去它左边的某一个元素可以得到一个差值,求所
: 有这些差值的最大值。不是最大值减去最小值,比如:
: {3, 4, 2, 7, 16, 1, 5, 11, 9}, 答案是16 - 2 = 14, 不是 16 - 1 = 15

avatar
g*e
8
二月底的飘过....
avatar
k*n
9
thx a lot
avatar
K*k
10
unsigned int MaxGain(int stock[], unsigned int N)
{
if (N < 2)
return 0;
int left_min = stock[0];
int max_gain = 0;
for (int i = 1; i < N; i++)
{
if (A[i] - left_min > max_gain)
max_gain = A[i] - left_min;
if (A[i] < left_min)
left_min = A[i];
}
return max_gain;
}
avatar
j*n
12
感觉在美帝没啥影响 回国可能会有

【在 k****n 的大作中提到】
: 有一片专业领域不错的文章马上要投了,老板说把我(我是一作)的地址加一个他在国
: 内大学地址,他在这个大学特聘兼职教授, 并且把国内地址改为第一地址,这边的地
: 址改为第二地址。他说主要是特聘要交差。请问这样对以后找工作没有什么影响吧。不
: 知道呀,求指点。

avatar
K*k
13
面经作者的写法是否稍微繁琐了一点?(变量太多,行数还能再少一点)
虽然思路是一样的?
我总觉得白板代码应该以简洁为美。
=====================================================================
int maxgain =0, best_buytime = 0, best_selltime =0; current_buytime=0;
current_selltime =0;
for (i = 1 to stock.length - 1)
{
if (stock[i] > stock[current_selltime])
{
current_selltime = i ;
// update maxgain if possible
int current_gain = stock[current_selltime] - stock[current_buytime];
if(current_gain > maxgain)
{
maxgain = current_gain ;
best_selltime = current_selltime;
best_buytime = current_buytime;
}
}
if (stock[i] < stock[current_buytime])
{
current_selltime = i;
current_buytime = i;
}
}

【在 b*******y 的大作中提到】
: 如果是long position的话,两个题目是一样的
: cracking google interview上面有解答
: 扫描一遍,maintain current min value以及maintain最大差值

avatar
v*b
14
Bless u got approved soon
avatar
k*o
15
回国也没影响。大家都知道怎么回事。

【在 j****n 的大作中提到】
: 感觉在美帝没啥影响 回国可能会有
avatar
m*k
16
you only tracked maxgain, the original question wants sell and buy time.
avatar
a*r
17
我也是二月中,苦等中。
avatar
s*x
18
If you are a postdoc or his employee, that's fine. But if you are a student,
I don't how your department will think. Of course, maybe they won't even
notice.
avatar
m*k
19
as my original post said, we can even compute the current local maxgain and
try to update global maxgain only when we get a new stock[i] < stock[current
_buyTime], this needs a dummy node at the end of stock[], otherwise we will
fail at [2, 3, 4, 5, 1, 2,3,4, 8] .
in this case [2, 3, 4, 5, 1, 2, 3 ,4, 8, -1(dummy node)],
we init with maxgain as 0, best_buy/best_sell as 0,
and current_buy/current_sell as 0,
then we move on starting from stock[1], only update current_sell again and
again since each stock[i] is greater than stock[current_sell], once we see
stock[i=4]==1 , 1 is smaller than stock[current_buy==0]==2, we know a new
local maxgain is coming, so we compute currently scanned local maxgain as
stock[current_sell]-stock[current_buy] = stock[3]-stock[0] = 5 -2 =3
and update global maxgain as 3, and remembers best_*,
then reset current_sell/current_buy to i=4,continue the loop, update current
_sell as we move along, when we reach -1, we compute local maxgain again and
get local maxgain as 8 - 1 =7, then update global maxgain again.
avatar
q*2
20
Bless!
avatar
k*n
21
Thanks a lot, not student.
avatar
K*k
22
如果要求buy time和sell time, 这样写就可以了么?
// Input: int stock[N]
// assert(N >= 2);
int min_index = 0;
int max_gain = 0;
int best_buytime = -1;
int best_selltime = -1;
for (int i = 1; i < N; i++)
{
if (stock[i] < stock[min_index])
min_index = i;
else if (stock[i] - stock[min_index] > max_gain)
{
max_gain = stock[i] - stock[min_index];
best_buytime = min_index;
best_selltime = i;
}
}
avatar
y*h
24
中国看第一单位
美国不看
avatar
s*8
25
二月初的,同等中~~
avatar
p*5
26
谢谢各位了。祝福我们大家。
avatar
s*8
27
big bless~~
avatar
b*M
28
TSC 485 是 7个月。
avatar
e*f
29
2月初的,不淡定的等待中。。。

【在 p********5 的大作中提到】
: TSC, 485, RD Mid January, still waiting.
avatar
a*e
30
2月底的,也在焦急等待中
avatar
f*e
31
BLESS! Hope we all get it soon...
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。