由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - Number 1~1000 with two of them missing.
相关主题
[合集] find a missing value(c++)one questions
借人气问题请教一个面试题
请教一道题的解法绿皮书最近会出第二版吗?
An interview question(math)摩根斯坦利HR第一轮电面题目
问一道编程题小女子弱问绿皮书的 random ants 一题
面试题(math)Ito's Lemma的问题
问三个编程面试题JP Morgan internship interview experience
gs superday后的悲剧+面试题目物理专业申金融界,要面试了,问一下经验 (转载)
相关话题的讨论汇总
话题: missing话题: int话题: number话题: result2话题: result1
进入Quant版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
How to find the missing two efficiently?
L**********u
发帖数: 194
2
这不是绿皮书上的原题吗?
x*****i
发帖数: 287
3
//b[1000] is the one we want to check
//
int a[1000] = {0};
for (int i = 0; i < 1000; i++ )
{
a[b[i]] = 1;
}
for (int i = 0; i < 1000; i++ )
{
if(a[i] == 0)
cout << "missing number : " << i << endl;
}
// don't know whether it is a sufficient algorithm or not. It is O(n)
c**********e
发帖数: 2007
4
Could you please post the answer on the green book? Thanks a lot!!!!!
Urgent help needed.

【在 L**********u 的大作中提到】
: 这不是绿皮书上的原题吗?
d*j
发帖数: 13780
5
要是没有重复的 就列个方程组
sum(x_i) = 一个常数
sum(x_i^2) = 另外一个常数

【在 c**********e 的大作中提到】
: Could you please post the answer on the green book? Thanks a lot!!!!!
: Urgent help needed.

L**********u
发帖数: 194
6
楼上的就是我说的绿皮书的做法呀
l*****a
发帖数: 14598
7
First ,i think the issue is that we have int a[998]
a[0]..a[997] store the number from 1..1000,missed 2 and no duplication
The best way from Computer science is below:
###pay attention that a^a=0
int result=0;
for(int i=0;i<997;i++)
{
result = result ^ a[i];
}
for(int i=1;i<1001;i++)
{
result = result ^ i;
}
###then result is just missing number1 ^ missing number2.
since they are different,there must be one digit is not the same of the two
number.
int index=1;
if!(result & 1< ### now index is the first different digit of number1/number2
###I will divide all the number into two group bu this digit,
then number1/number2 are the only missing number in their group
int result1=0;
int result2=0;
for(int i=0;i<997;i++)
{
if(a[i] & 1< else result2 = result2 ^ a[i];
}
for(int i=1;i<1001;i++)
{
if(i & 1< else result2 = result2 ^ i;
}
result1,result2 are just the two missing number
time complexity O(n)
space complexity O(1)

【在 c**********e 的大作中提到】
: How to find the missing two efficiently?
l*****a
发帖数: 14598
8
u need extra space

【在 x*****i 的大作中提到】
: //b[1000] is the one we want to check
: //
: int a[1000] = {0};
: for (int i = 0; i < 1000; i++ )
: {
: a[b[i]] = 1;
: }
: for (int i = 0; i < 1000; i++ )
: {
: if(a[i] == 0)

1 (共1页)
进入Quant版参与讨论
相关主题
物理专业申金融界,要面试了,问一下经验 (转载)问一道编程题
发面经barclays capital面试题(math)
哪位去多BARCLAYS ONSITE 呀?问三个编程面试题
一道上楼梯的问题gs superday后的悲剧+面试题目
[合集] find a missing value(c++)one questions
借人气问题请教一个面试题
请教一道题的解法绿皮书最近会出第二版吗?
An interview question(math)摩根斯坦利HR第一轮电面题目
相关话题的讨论汇总
话题: missing话题: int话题: number话题: result2话题: result1