Redian新闻
>
att上6s的ship date都是9/24, 6s plus都是10/16之后那一周
avatar
att上6s的ship date都是9/24, 6s plus都是10/16之后那一周# Apple - 家有苹果
h*d
1
都是前两个礼拜面的,下个礼拜2面,来攒个rp
AMAZON
1. Research
2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
), replaceAll()
3. 合并2个BST, 要求O(n)time
4. 2个stack -> 1个queue
GOOGLE
1. Research 因为我是做NLP的,machine learning涉及了一些,问的比较细,有点烦。
。。
2. 找一个string出现最多的字母,扩展问了很多,内存,多核CPU,多个多核CPU
machine...一开始给的hashmap的解法最后combine会有点问题,反正吭哧吭哧的答了,
最后自己觉得并没有improve多少time complexity..
祝福以下大家和自己
avatar
d*n
2
看来货源充足。
avatar
p*1
3
谢谢分享!Bless!
avatar
w*r
4
6s plus ship date 9/25的飘过
verizon版

【在 d****n 的大作中提到】
: 看来货源充足。
avatar
d*u
5
bless u
avatar
t*0
6
bless
avatar
c*t
7
bless

replace(

【在 h**********d 的大作中提到】
: 都是前两个礼拜面的,下个礼拜2面,来攒个rp
: AMAZON
: 1. Research
: 2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
: ), replaceAll()
: 3. 合并2个BST, 要求O(n)time
: 4. 2个stack -> 1个queue
: GOOGLE
: 1. Research 因为我是做NLP的,machine learning涉及了一些,问的比较细,有点烦。
: 。。

avatar
i*9
8
合并2个BST, 要求O(n)time,
flatten two bst by in order traversal ,and rebuild a bigger bst, 有更直接的
办法吗

replace(

【在 h**********d 的大作中提到】
: 都是前两个礼拜面的,下个礼拜2面,来攒个rp
: AMAZON
: 1. Research
: 2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
: ), replaceAll()
: 3. 合并2个BST, 要求O(n)time
: 4. 2个stack -> 1个queue
: GOOGLE
: 1. Research 因为我是做NLP的,machine learning涉及了一些,问的比较细,有点烦。
: 。。

avatar
t*0
9
this looks like nlgn



【在 i**9 的大作中提到】
: 合并2个BST, 要求O(n)time,
: flatten two bst by in order traversal ,and rebuild a bigger bst, 有更直接的
: 办法吗
:
: replace(

avatar
t*0
10
if a merge sort is used..

【在 t****0 的大作中提到】
: this looks like nlgn
:
: 的

avatar
b*u
11
bless
avatar
i*9
12
merging two sorted array takes O(n)

【在 t****0 的大作中提到】
: this looks like nlgn
:
: 的

avatar
g*s
13
这个算法确实是线性的,但代码写起来还挺繁琐:
1) in-order traverse and merge bst T1 and T2 into a sorted array X,
O(N+M).
2) create a balanced bt T with N+M nodes, can be achieved by O(N+M) but
the # of node at each level needs some calculation with patience.
3) in-order traverse T and fill up T with X.



【在 i**9 的大作中提到】
: 合并2个BST, 要求O(n)time,
: flatten two bst by in order traversal ,and rebuild a bigger bst, 有更直接的
: 办法吗
:
: replace(

avatar
t*0
14
2) it seems not requiring balanced...
http://stackoverflow.com/questions/4235013/create-balanced-bina
search-tree-from-sorted-linked-list
BinaryTree* sortedListToBST(ListNode *& list, int start, int end) {
if (start > end) return NULL;
// same as (start+end)/2, avoids overflow
int mid = start + (end - start) / 2;
BinaryTree *leftChild = sortedListToBST(list, start, mid-1);
BinaryTree *parent = new BinaryTree(list->data);
parent->left = leftChild;
list = list->next;
parent->right = sortedListToBST(list, mid+1, end);
return parent;
}
BinaryTree* sortedListToBST(ListNode *head, int n) {
return sortedListToBST(head, 0, n-1);

but

【在 g*********s 的大作中提到】
: 这个算法确实是线性的,但代码写起来还挺繁琐:
: 1) in-order traverse and merge bst T1 and T2 into a sorted array X,
: O(N+M).
: 2) create a balanced bt T with N+M nodes, can be achieved by O(N+M) but
: the # of node at each level needs some calculation with patience.
: 3) in-order traverse T and fill up T with X.
:
: 的

avatar
g*s
15
then how to maintain the balanced property?

【在 t****0 的大作中提到】
: 2) it seems not requiring balanced...
: http://stackoverflow.com/questions/4235013/create-balanced-bina
: search-tree-from-sorted-linked-list
: BinaryTree* sortedListToBST(ListNode *& list, int start, int end) {
: if (start > end) return NULL;
: // same as (start+end)/2, avoids overflow
: int mid = start + (end - start) / 2;
: BinaryTree *leftChild = sortedListToBST(list, start, mid-1);
: BinaryTree *parent = new BinaryTree(list->data);
: parent->left = leftChild;

avatar
h*d
16
对对,我忘记说了,是两个balanced 大小都为n nodes的bst

【在 t****0 的大作中提到】
: 2) it seems not requiring balanced...
: http://stackoverflow.com/questions/4235013/create-balanced-bina
: search-tree-from-sorted-linked-list
: BinaryTree* sortedListToBST(ListNode *& list, int start, int end) {
: if (start > end) return NULL;
: // same as (start+end)/2, avoids overflow
: int mid = start + (end - start) / 2;
: BinaryTree *leftChild = sortedListToBST(list, start, mid-1);
: BinaryTree *parent = new BinaryTree(list->data);
: parent->left = leftChild;

avatar
h*d
17
我一开始就说了个nlogn的bst insertion,他说要o(n)的,不在乎space
然后我就说了这个笨办法,不知道有没有更好的,不过他seems满意

直接的

【在 i**9 的大作中提到】
: 合并2个BST, 要求O(n)time,
: flatten two bst by in order traversal ,and rebuild a bigger bst, 有更直接的
: 办法吗
:
: replace(

avatar
g*s
18
how do u guarantee this is a balanced bst? the left and right sub-tree
might have unequal number of nodes.

【在 t****0 的大作中提到】
: 2) it seems not requiring balanced...
: http://stackoverflow.com/questions/4235013/create-balanced-bina
: search-tree-from-sorted-linked-list
: BinaryTree* sortedListToBST(ListNode *& list, int start, int end) {
: if (start > end) return NULL;
: // same as (start+end)/2, avoids overflow
: int mid = start + (end - start) / 2;
: BinaryTree *leftChild = sortedListToBST(list, start, mid-1);
: BinaryTree *parent = new BinaryTree(list->data);
: parent->left = leftChild;

avatar
g*s
19
how about the merged bst? is it required to be balanced?

【在 h**********d 的大作中提到】
: 我一开始就说了个nlogn的bst insertion,他说要o(n)的,不在乎space
: 然后我就说了这个笨办法,不知道有没有更好的,不过他seems满意
:
: 直接的

avatar
h*d
20
对,最后的bst也应该是balanced
所有操作都应该是O(n)

【在 g*********s 的大作中提到】
: how about the merged bst? is it required to be balanced?
avatar
g*s
21
then how did u ensure the merged bst is balanced?

【在 h**********d 的大作中提到】
: 对,最后的bst也应该是balanced
: 所有操作都应该是O(n)

avatar
h*d
22
就是从一个sorted array建立balanced bst
Node sortedArrayToBST(int[] a, int l, int r){
if(l > r){return null;}
int mid = l+(r-l)/2;
Node root = new Node(a[mid]);
root.setLeft(sortedArrayToBST(a, l, mid-1));
root.setRight(sortedArrayToBST(a, mid, r));
return root;
}

【在 g*********s 的大作中提到】
: then how did u ensure the merged bst is balanced?
avatar
g*s
23
sorry, but can u prove this is balanced? i believe this algorithm creates
a bst. but i'm not convinced the created bst is balanced.
u can see the left and right sub-tree can have size difference by 1. if u
do recursion, then is it possible at each level the left and right may
have difference by 1? if so the worst case this difference is accumulated
with an O(lgN) bound...

【在 h**********d 的大作中提到】
: 就是从一个sorted array建立balanced bst
: Node sortedArrayToBST(int[] a, int l, int r){
: if(l > r){return null;}
: int mid = l+(r-l)/2;
: Node root = new Node(a[mid]);
: root.setLeft(sortedArrayToBST(a, l, mid-1));
: root.setRight(sortedArrayToBST(a, mid, r));
: return root;
: }

avatar
m*i
24
2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
), replaceAll()
2. 找一个string出现最多的字母,扩展问了很多,内存,多核CPU,多个多核CPU
machine...一开始给的hashmap的解法最后combine会有点问题,反正吭哧吭哧的答了,
最后自己觉得并没有improve多少time complexity..
这两个可以详细说说么
avatar
m*i
25

creates
u
accumulated
2 BSTs have n nodes each, therefore, the combined sorted array is even
size. It can guarantee that the left and right subtree are equal size.

【在 g*********s 的大作中提到】
: sorry, but can u prove this is balanced? i believe this algorithm creates
: a bst. but i'm not convinced the created bst is balanced.
: u can see the left and right sub-tree can have size difference by 1. if u
: do recursion, then is it possible at each level the left and right may
: have difference by 1? if so the worst case this difference is accumulated
: with an O(lgN) bound...

avatar
g*s
26
how? if size(left) == size(right), then total node # is 2k + 1 counting
the root, while the array size is even as u said. a contradiction.

【在 m****i 的大作中提到】
:
: creates
: u
: accumulated
: 2 BSTs have n nodes each, therefore, the combined sorted array is even
: size. It can guarantee that the left and right subtree are equal size.

avatar
m*i
27

Actually, you are right the left and right subtree have 1 node different.
however, by definition, the balanced tree does not mean left and right
subtree must have equal size.
From wiki
a self-balancing (or height-balanced) binary search tree is any node
based binary search tree that automatically keeps its height (number of
levels below the root) small in the face of arbitrary item insertions and
deletion

【在 g*********s 的大作中提到】
: how? if size(left) == size(right), then total node # is 2k + 1 counting
: the root, while the array size is even as u said. a contradiction.

avatar
g*s
28
by definition, balanced bst must have the min leaf node level and max
leaf node level difference O(1). by doing this, the max height is
guaranteed to be O(logN) and this is the foundation for O(logN)
operations insert, delete, etc.
but in ur solution, the left and right sub-tree are not identical. and
the left of left and right of left are possibly not identical too. so
the min/max leaf could possibly non-zero. and this diff can accumulate
and breaks the O(1) bound.
unless there's a solid proof of the balanced property. but i can't
figure it out.
my solution is to build a complete binary tree first, which is
guaranteed to be balanced. but this solution is lengthy. so i would be
happy to see an elegant and correctness proven solution.

different.
of
and

【在 m****i 的大作中提到】
:
: Actually, you are right the left and right subtree have 1 node different.
: however, by definition, the balanced tree does not mean left and right
: subtree must have equal size.
: From wiki
: a self-balancing (or height-balanced) binary search tree is any node
: based binary search tree that automatically keeps its height (number of
: levels below the root) small in the face of arbitrary item insertions and
: deletion

avatar
i*e
29
Please don't get confuse :)
I don't know what you mean by min leaf node and max leaf node. Is it the
node that has min and max values? If it is, then your definition of balanced
bst is wrong.
The correct definition for a balanced bst is:
A tree whose subtrees differ in height by no more than one and the subtrees
are height-balanced, too.
When you subdivide the array and construct the bst top-down, you are
essentially maintaining the following invariant in each subdivision:
|#nodes in left subtree - #nodes in right subtree| = either 0 or 1.
If you want a unbalanced subtree, according to the definition you have to
generate two subtrees where height is differ by two (or above). This means
that in one of the subtree you need at least two level of subdivisions more
than the other subtree. This is impossible as the absolute difference
between the #nodes of both subtrees are at most 1, and each time you
subdivide in the center.
If you still don't understand, try to draw two arrays, where the #elements
in left array is N, and #elements in right array is N+1. Each time you would
subdivide in the middle of the array to two sub-arrays. Could you end up
with where the # of subdivisions of the left array and the # of subdivisions
of the right array differ by two or above?
This is impossible. Therefore, by proof of contradiction the bst must be
balanced. (I know this proof is not solid enough, but you get the idea.)
一些常见面试题的答案与总结 -
http://www.ihas1337code.com

【在 g*********s 的大作中提到】
: by definition, balanced bst must have the min leaf node level and max
: leaf node level difference O(1). by doing this, the max height is
: guaranteed to be O(logN) and this is the foundation for O(logN)
: operations insert, delete, etc.
: but in ur solution, the left and right sub-tree are not identical. and
: the left of left and right of left are possibly not identical too. so
: the min/max leaf could possibly non-zero. and this diff can accumulate
: and breaks the O(1) bound.
: unless there's a solid proof of the balanced property. but i can't
: figure it out.

avatar
h*d
30
你跑一下code试试吧,大家解释都不清楚
这个算法是给出层树最小的树,不会向你说的accumulated

【在 g*********s 的大作中提到】
: sorry, but can u prove this is balanced? i believe this algorithm creates
: a bst. but i'm not convinced the created bst is balanced.
: u can see the left and right sub-tree can have size difference by 1. if u
: do recursion, then is it possible at each level the left and right may
: have difference by 1? if so the worst case this difference is accumulated
: with an O(lgN) bound...

avatar
h*d
31
这题我以前看过
String replaceString(String string, String oldString, String newString){
if(string == null || oldString == null || newString == null){
throw new IllegalArgumentException("Null arguments");
}
if(oldString.equals("")){
throw new IllegalArgumentException("oldString has no content");
}
StringBuilder result = new StringBuilder();
int i = 0;
int j = 0;
while((j = string.indexOf(oldString, i)) >= 0){
result.append(string.substring(i, j));
result.append(newString);
i = j + oldString.length();
}
result.append(string.substring(i));
return result.toString();
}
GOOGLE那题
我就说用hashmap遍历记录count,或者用sort,但是没有前者快
他说就用hashmap把。然后多机多CPU的就把array分段分别处理,但是那样返回的各个
count是subarray的count,不好加起来吧,然后自己就有点晕了。。。。最后我说返回
hashmap,然后再数。。。。他说ok,但自己觉得答的很差
我不知道他说多core机器和多个机器到底要怎样的答案,我除了para computing也想不
出啥

replace(

【在 m****i 的大作中提到】
: 2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
: ), replaceAll()
: 2. 找一个string出现最多的字母,扩展问了很多,内存,多核CPU,多个多核CPU
: machine...一开始给的hashmap的解法最后combine会有点问题,反正吭哧吭哧的答了,
: 最后自己觉得并没有improve多少time complexity..
: 这两个可以详细说说么

avatar
i*d
32
mapreduce?

【在 h**********d 的大作中提到】
: 这题我以前看过
: String replaceString(String string, String oldString, String newString){
: if(string == null || oldString == null || newString == null){
: throw new IllegalArgumentException("Null arguments");
: }
: if(oldString.equals("")){
: throw new IllegalArgumentException("oldString has no content");
: }
: StringBuilder result = new StringBuilder();
: int i = 0;

avatar
b*r
33
你这两个都是电话面试吧 怎么还要2面 应该是onsite了吧
avatar
b*r
34
merge两个bst应该很简单吧
in order traverse之后就是2个sorted array了 然后用merge sort的merge
3个operation都是o(n) 所以total就是o(n)
avatar
h*4
35
bless
avatar
d*b
36
看看这个Web Developer的求职网站:
http://jobguideweb.com/engineer-jobs/web-developer-jobs.html

replace(

【在 h**********d 的大作中提到】
: 都是前两个礼拜面的,下个礼拜2面,来攒个rp
: AMAZON
: 1. Research
: 2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
: ), replaceAll()
: 3. 合并2个BST, 要求O(n)time
: 4. 2个stack -> 1个queue
: GOOGLE
: 1. Research 因为我是做NLP的,machine learning涉及了一些,问的比较细,有点烦。
: 。。

avatar
E*n
37

replace(
这个replaceAll的第一个参数是regex,如果是replaceAll("[a-c][0-9]", "a"),怎么实
现它?还是他们只要你实现字符串替换字符串就行了?

【在 h**********d 的大作中提到】
: 都是前两个礼拜面的,下个礼拜2面,来攒个rp
: AMAZON
: 1. Research
: 2. 实现Java String class的repleaceAll() method,不可以用String本身的replace(
: ), replaceAll()
: 3. 合并2个BST, 要求O(n)time
: 4. 2个stack -> 1个queue
: GOOGLE
: 1. Research 因为我是做NLP的,machine learning涉及了一些,问的比较细,有点烦。
: 。。

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