boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Splunk面经 (转载)
相关主题
不用暴力,这道题有没有优化解
G家这道题怎么做的?
splunk面经,攒人品
Palantir面经2
msft校园面经 amazon三次电面面经
[合集] G家onsite面经
写一个function判断一个数是不是2的整数次方
新鲜SDET M onsite 面经 [update offer]
Epic Offer, 该不该从, 贴一些面经
Google面经,同求大牛refer
相关话题的讨论汇总
话题: uint话题: int话题: bool话题: return话题: problem
进入JobHunting版参与讨论
1 (共1页)
kx
发帖数: 16384
1
【 以下文字转载自 Dreamer 讨论区 】
发信人: Dreamer (不要问我从哪里来), 信区: Dreamer
标 题: (麻烦转到jobhunting版)Splunk面经
发信站: BBS 未名空间站 (Fri Nov 1 12:33:13 2013, 美东)
--------------------------------------------
对方发来email,要求找以下三段code有什么问题:
1.
bool f(int x)
{
return !(x & 7);
}
2.
uint v[10];
uint i = 0;
while (i < 10)
v[i] = i++;
3.
bool f( uint n )
{
return (n & (n-1)) == 0;
}
这道题我只找到一个问题,就是调用f(n)时如果n是INT_MIN,那么返回true。
--------------------------------------------
s***e
发帖数: 403
2
这些函数的目的是什么?不给目的的话,只要不潜在crash就是正确的。
l***i
发帖数: 1309
3
problem 2, undefined behavior, because i is used in lhs and rhs and it is
not defined which side gets evaluated first
l***i
发帖数: 1309
4
problem 1 seems to check whether input is a multiple of 8, since it masks
all high order bits, but then there is a problem if input is negative.
w********g
发帖数: 106
5
which negative input causes problem? I checked 0, -8, -16, and -2147483648
(-2^31), all return true.

【在 l***i 的大作中提到】
: problem 1 seems to check whether input is a multiple of 8, since it masks
: all high order bits, but then there is a problem if input is negative.

a***m
发帖数: 5037
6
C99 specification: "Between the previous and next sequence point an object
shall have its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to determine
the value to be stored."
google : sequence point
   
kx
发帖数: 16384
7
【 以下文字转载自 Dreamer 讨论区 】
发信人: Dreamer (不要问我从哪里来), 信区: Dreamer
标 题: (麻烦转到jobhunting版)Splunk面经
发信站: BBS 未名空间站 (Fri Nov 1 12:33:13 2013, 美东)
--------------------------------------------
对方发来email,要求找以下三段code有什么问题:
1.
bool f(int x)
{
return !(x & 7);
}
2.
uint v[10];
uint i = 0;
while (i < 10)
v[i] = i++;
3.
bool f( uint n )
{
return (n & (n-1)) == 0;
}
这道题我只找到一个问题,就是调用f(n)时如果n是INT_MIN,那么返回true。
--------------------------------------------
s***e
发帖数: 403
8
这些函数的目的是什么?不给目的的话,只要不潜在crash就是正确的。
l***i
发帖数: 1309
9
problem 2, undefined behavior, because i is used in lhs and rhs and it is
not defined which side gets evaluated first
l***i
发帖数: 1309
10
problem 1 seems to check whether input is a multiple of 8, since it masks
all high order bits, but then there is a problem if input is negative.
w********g
发帖数: 106
11
which negative input causes problem? I checked 0, -8, -16, and -2147483648
(-2^31), all return true.

【在 l***i 的大作中提到】
: problem 1 seems to check whether input is a multiple of 8, since it masks
: all high order bits, but then there is a problem if input is negative.

a***m
发帖数: 5037
12
C99 specification: "Between the previous and next sequence point an object
shall have its stored value modified at most once by the evaluation of an
expression. Furthermore, the prior value shall be accessed only to determine
the value to be stored."
google : sequence point
   
f******n
发帖数: 346
13
看不出来1有什么毛病,8 变成-8 是反转然后+1,
00001000 -> 11111000
mask 是00000111,没有错啊
c********p
发帖数: 1969
14
mark
1 (共1页)
进入JobHunting版参与讨论
相关主题
Google面经,同求大牛refer
zenefit 电面面经
T家在线测试面经,感觉好难啊
这道题不会
Qualcomm的面经
谁帮我看看这个8皇后问题
frontend 面经
面经-facebook, amazon,telenav, quantcast
问一个facebook的电面题
atoi的溢出处理的想法
相关话题的讨论汇总
话题: uint话题: int话题: bool话题: return话题: problem