由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Amazon first phone interview
相关主题
请教leetcode上的count and saylengthOfLongestSubstring 最后一个test case总是超时
周末上道小题吧anagram的A家面试题
LC 387 怎么优化一道电面题,分享下, 这个题应该用哪几个data structure?
一道面试题(integer to binary string)纽约附近小公司电面 Amplify;MLB;Portware;Saks,BOA
input a string "hello word", print l:3 o:2 e:1 d:1 h:1 r:1 w:1.不知道哪错了请教一个phone interview 问题
一FG家常见题google 一题
share int2roman and roman2int java version一个答案看不明白谁解释一下
问一下OJ的Anagrams那道题用bst怎么实现hashtable?
相关话题的讨论汇总
话题: string话题: integer话题: character话题: map
进入JobHunting版参与讨论
1 (共1页)
k**8
发帖数: 186
1
1. talk about your projects (more details were asked)
2. whats BST
3. how to implement BST(more specific details here)
4. how to identify an integer is a power of 2
5. Sort string a based on the order of the letters in string b.
For example: a = cat, b = tar, sorted = tac
All above took about 1 hour.
g***j
发帖数: 1275
2
最后一题怎么回答的啊?
可以不可以搞一个map,把字母和数字重新对应?
t - 1
a - 2
r - 3
然后 cat 就是421 排序之后,就是 124,然后再映射回来,就是tac啦?

【在 k**8 的大作中提到】
: 1. talk about your projects (more details were asked)
: 2. whats BST
: 3. how to implement BST(more specific details here)
: 4. how to identify an integer is a power of 2
: 5. Sort string a based on the order of the letters in string b.
: For example: a = cat, b = tar, sorted = tac
: All above took about 1 hour.

j*****s
发帖数: 189
3
怎么得到phone interview的机会的?求指导啊。

【在 k**8 的大作中提到】
: 1. talk about your projects (more details were asked)
: 2. whats BST
: 3. how to implement BST(more specific details here)
: 4. how to identify an integer is a power of 2
: 5. Sort string a based on the order of the letters in string b.
: For example: a = cat, b = tar, sorted = tac
: All above took about 1 hour.

p*****2
发帖数: 21240
4

写一个comparator就可以了吧?

【在 g***j 的大作中提到】
: 最后一题怎么回答的啊?
: 可以不可以搞一个map,把字母和数字重新对应?
: t - 1
: a - 2
: r - 3
: 然后 cat 就是421 排序之后,就是 124,然后再映射回来,就是tac啦?

g***j
发帖数: 1275
5
是的
但是comparator里面如何定义俩字母的相对大小呢?

【在 p*****2 的大作中提到】
:
: 写一个comparator就可以了吧?

r*****i
发帖数: 26
6
确实要搞个map,把字母映射到出现的位置,然后再用comparator就可以了。问题是如
果a和b不同字母的个数多于一个的话,这种映射是不是会有二义性啊?

【在 g***j 的大作中提到】
: 是的
: 但是comparator里面如何定义俩字母的相对大小呢?

e****e
发帖数: 418
7
IMHO, the limitation of this question is b shouldn't have dups.
public String sort(String input, String order) {
Map map = new LinkedHashMap(
);

for ( int i = 0; i < order.length(); i++ )
map.put( order.charAt( i ), 0 );

for ( int i = 0; i < input.length(); i++ ) {
char c = input.charAt( i );
if ( map.containsKey( c ) )
map.put( c , map.get(c) + 1 );
else
map.put( c , 1 );
}

StringBuffer sb = new StringBuffer();
for ( Map.Entry entry : map.entrySet() ) {
for ( int i = 0; i < entry.getValue(); i++ )
sb.append( entry.getKey() );
}

return sb.toString();
}

【在 r*****i 的大作中提到】
: 确实要搞个map,把字母映射到出现的位置,然后再用comparator就可以了。问题是如
: 果a和b不同字母的个数多于一个的话,这种映射是不是会有二义性啊?

k****r
发帖数: 807
8
F********9
发帖数: 44
9
comparator, 加个构造函数参数。
char array[26] = {0};
i = 0;
for c in str:
array[c] = ++i;
重载operator(),直接查值就行了,不用散列那么麻烦。

【在 r*****i 的大作中提到】
: 确实要搞个map,把字母映射到出现的位置,然后再用comparator就可以了。问题是如
: 果a和b不同字母的个数多于一个的话,这种映射是不是会有二义性啊?

c**m
发帖数: 535
10
赞!
预祝你过两天的M电面顺利
l*****a
发帖数: 14598
11
顺序怎么定的,没看懂
另外如果支持大小写怎么办,支持unicode怎么办?支持无穷大字符集怎么办?

【在 F********9 的大作中提到】
: comparator, 加个构造函数参数。
: char array[26] = {0};
: i = 0;
: for c in str:
: array[c] = ++i;
: 重载operator(),直接查值就行了,不用散列那么麻烦。

d**s
发帖数: 98
12
Thanks!

【在 k**8 的大作中提到】
: 1. talk about your projects (more details were asked)
: 2. whats BST
: 3. how to implement BST(more specific details here)
: 4. how to identify an integer is a power of 2
: 5. Sort string a based on the order of the letters in string b.
: For example: a = cat, b = tar, sorted = tac
: All above took about 1 hour.

1 (共1页)
进入JobHunting版参与讨论
相关主题
用bst怎么实现hashtable?input a string "hello word", print l:3 o:2 e:1 d:1 h:1 r:1 w:1.不知道哪错了
LRU question一FG家常见题
问个关于排序的面试题share int2roman and roman2int java version
问两道G家的题问一下OJ的Anagrams那道题
请教leetcode上的count and saylengthOfLongestSubstring 最后一个test case总是超时
周末上道小题吧anagram的A家面试题
LC 387 怎么优化一道电面题,分享下, 这个题应该用哪几个data structure?
一道面试题(integer to binary string)纽约附近小公司电面 Amplify;MLB;Portware;Saks,BOA
相关话题的讨论汇总
话题: string话题: integer话题: character话题: map