avatar
拿出芭蕉扇扇扇# Joke - 肚皮舞运动
r*l
1
Given an unsorted array A[] with size (100 - k), the elements in the array
are unique numbers from 1 to 100.
Apparently there are k numbers are missing. Give a linear time and constant
space solution to find the k
missing numbers.
Any thoughts?
avatar
J*y
2
在 Part 5, 如果我DIY 140表 (没找律师),我应该填 2if a company 还是填:3
if an individual.
谢谢
Part 5. Additional information about the petitioner.
1. Type of petitioner
[x] Employer
[ ] Self
2. If a company, give the following:
Type of Business
Date Established (mm/dd/yyyy)
Current Number of Employees
Gross Annual Income
Net Annual Income
NAICS Code
DOL/ETA Case Number
3. If an individual, give the following:
Occupation
Annual Income
avatar
x*a
3
以前同学读课文,其中有一句:拿出芭蕉扇扇扇。本来停顿应该是拿出芭蕉扇,扇扇。
那同学直接读成:拿出芭蕉,扇扇扇!
avatar
g*s
4
Discussed in the last month. in-place swap the i to (i-1)-th of the array.

array
constant

【在 r****l 的大作中提到】
: Given an unsorted array A[] with size (100 - k), the elements in the array
: are unique numbers from 1 to 100.
: Apparently there are k numbers are missing. Give a linear time and constant
: space solution to find the k
: missing numbers.
: Any thoughts?

avatar
x*S
5
Eb1B has to be sponsored by your employer.
So, Part 5
you should fill out the information about your company. No need to fill
out your information here, which will be needed in part 6.
avatar
f*l
6
LOL.

【在 x*****a 的大作中提到】
: 以前同学读课文,其中有一句:拿出芭蕉扇扇扇。本来停顿应该是拿出芭蕉扇,扇扇。
: 那同学直接读成:拿出芭蕉,扇扇扇!

avatar
c*e
7
Could you give more information for " in-place swap the i to (i-1)-th of the
array." ? Thanks
avatar
J*y
8
THANKS
avatar
P*r
9
Just create an array A[100] initialized to 0, and iterate the numbers, say i
, set A[i]=1. Then the index j of the array with A[j]==0 is the number
missing.
avatar
G*o
10
this solution requires O(n) space, not constant

i

【在 P******r 的大作中提到】
: Just create an array A[100] initialized to 0, and iterate the numbers, say i
: , set A[i]=1. Then the index j of the array with A[j]==0 is the number
: missing.

avatar
s*y
11
Just 0 ~ 100 ? So it only occupy 6 bits.
Could you use the highest 6 bits to be your hash bit?
It maybe more easier than swap then.

【在 G*********o 的大作中提到】
: this solution requires O(n) space, not constant
:
: i

avatar
r*l
12

But the space complexity would be dependent on N

【在 s*****y 的大作中提到】
: Just 0 ~ 100 ? So it only occupy 6 bits.
: Could you use the highest 6 bits to be your hash bit?
: It maybe more easier than swap then.

avatar
r*l
13

I got the idea, thanks!

【在 g***s 的大作中提到】
: Discussed in the last month. in-place swap the i to (i-1)-th of the array.
:
: array
: constant

avatar
s*y
14
why you need space?
you set the bits of the array in place.

【在 r****l 的大作中提到】
:
: I got the idea, thanks!

avatar
r*l
15

you mean use one of the element space as a bitmap?
I think it'll work, and we can also reset that element after find out all
missing numbers, thus the array will
remain unchanged.
Cool.

【在 s*****y 的大作中提到】
: why you need space?
: you set the bits of the array in place.

avatar
s*y
16
yes.

【在 r****l 的大作中提到】
:
: you mean use one of the element space as a bitmap?
: I think it'll work, and we can also reset that element after find out all
: missing numbers, thus the array will
: remain unchanged.
: Cool.

avatar
B*t
17
这样只能找到1-sizeof array之间的missing,不是1-100之间的

【在 g***s 的大作中提到】
: Discussed in the last month. in-place swap the i to (i-1)-th of the array.
:
: array
: constant

avatar
g*s
19
can we assume k<=n/2?
then use this method again.

【在 B*******t 的大作中提到】
: 这样只能找到1-sizeof array之间的missing,不是1-100之间的
avatar
B*t
20
then how to do inplace? You lose data in the first pass.

【在 g***s 的大作中提到】
: can we assume k<=n/2?
: then use this method again.

avatar
g*s
21
m = length of the array
first time, skip all numbers > m
inplance swap, scan find all mising number beteen 1 and m.
then, only check all numbers > m,
inplance to swap these number to (i-1)-m th
scan find all missing number between m+1 and n

【在 B*******t 的大作中提到】
: then how to do inplace? You lose data in the first pass.
avatar
g*e
22
学习

【在 g***s 的大作中提到】
: m = length of the array
: first time, skip all numbers > m
: inplance swap, scan find all mising number beteen 1 and m.
: then, only check all numbers > m,
: inplance to swap these number to (i-1)-m th
: scan find all missing number between m+1 and n

avatar
B*t
23
多谢,学习一下

【在 g***s 的大作中提到】
: m = length of the array
: first time, skip all numbers > m
: inplance swap, scan find all mising number beteen 1 and m.
: then, only check all numbers > m,
: inplance to swap these number to (i-1)-m th
: scan find all missing number between m+1 and n

avatar
g*s
24
这是哪家?

array
constant

【在 r****l 的大作中提到】
: Given an unsorted array A[] with size (100 - k), the elements in the array
: are unique numbers from 1 to 100.
: Apparently there are k numbers are missing. Give a linear time and constant
: space solution to find the k
: missing numbers.
: Any thoughts?

avatar
f*4
25
这个题目,要是我用 k个space,算是constant space么?
avatar
k*p
26
感觉有点小小的漏洞,如果m很小,比如20,那你得分5段筛选吧。

【在 g***s 的大作中提到】
: m = length of the array
: first time, skip all numbers > m
: inplance swap, scan find all mising number beteen 1 and m.
: then, only check all numbers > m,
: inplance to swap these number to (i-1)-m th
: scan find all missing number between m+1 and n

avatar
r*r
27
如果是排序的,就简单吧。里面那个打印的 for loop 不算,就是 O(n). 便于测试,
假设从 10 个中找 k missing number.
Input: int[] a = {4, 5, 7, 10};
int k = 6;
Output: 1 2 3 6 8 9
public static void findMissing(int[] a, int k){
int l =1;
int i =0;
while(i<10-k){
int diff = a[i]-l;
if(diff == 0){
i++;
l++;
}else{
int big = a[i];
for(int j=l; jSystem.out.print(" " + j);
l++;
}

}
}
if( l <= 10 ){
while( l <= 10){
System.out.println(" " + l);
l++;
}
}
}
如果是 unsorted,就不行了
avatar
r*r
28
对了,看见题目里面说 unsorted,not work.
sorry.

【在 r******r 的大作中提到】
: 如果是排序的,就简单吧。里面那个打印的 for loop 不算,就是 O(n). 便于测试,
: 假设从 10 个中找 k missing number.
: Input: int[] a = {4, 5, 7, 10};
: int k = 6;
: Output: 1 2 3 6 8 9
: public static void findMissing(int[] a, int k){
: int l =1;
: int i =0;
: while(i<10-k){
: int diff = a[i]-l;

avatar
g*s
29
that's true.
That's why I said: assume m>= n/2 based on the word 'missing'.

【在 k*******p 的大作中提到】
: 感觉有点小小的漏洞,如果m很小,比如20,那你得分5段筛选吧。
avatar
q*9
30
那还叫missing么,那应该是在数组里的叫missing了

【在 k*******p 的大作中提到】
: 感觉有点小小的漏洞,如果m很小,比如20,那你得分5段筛选吧。
avatar
a*m
31
用bool flags[100]算不算constant space?

constant

【在 r****l 的大作中提到】
: Given an unsorted array A[] with size (100 - k), the elements in the array
: are unique numbers from 1 to 100.
: Apparently there are k numbers are missing. Give a linear time and constant
: space solution to find the k
: missing numbers.
: Any thoughts?

avatar
h*n
32
先在数组结尾补k个-1
for i in range(len(list)):
while list[i] != i:
if(list[i]==-1):
break
temp = list[i]
list[i] = list[list[i]]
list[temp] = temp
每次至少把一个数放到自己的位置上
最后扫描一遍,-1都在missing number的位置上

【在 a********m 的大作中提到】
: 用bool flags[100]算不算constant space?
:
: constant

avatar
s*n
33
算,不然为什么说100-k, 而不是简单的n-k.

【在 a********m 的大作中提到】
: 用bool flags[100]算不算constant space?
:
: constant

avatar
a*m
34
那用标记数组不就可以了?

【在 s*****n 的大作中提到】
: 算,不然为什么说100-k, 而不是简单的n-k.
avatar
P*c
35
数组结尾可以随便补吗?万一定义的数组长度就是100-k呢。

【在 h*********n 的大作中提到】
: 先在数组结尾补k个-1
: for i in range(len(list)):
: while list[i] != i:
: if(list[i]==-1):
: break
: temp = list[i]
: list[i] = list[list[i]]
: list[temp] = temp
: 每次至少把一个数放到自己的位置上
: 最后扫描一遍,-1都在missing number的位置上

avatar
s*n
36
两个int64或者long long就搞定了。

【在 a********m 的大作中提到】
: 那用标记数组不就可以了?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。