Redian新闻
>
求点评:电话面试(今天第二天没有消息回复,感觉可能挂了)
avatar
求点评:电话面试(今天第二天没有消息回复,感觉可能挂了)# JobHunting - 待字闺中
x*y
1
以下是code面试题目,和我给的答案。答案有错,我标识了出来。请各位点评一下,进
一步提高!多谢!!!
面试管是印度人,
第一步,讨论解法:要求用实例,我给了 array (1,9,2,3,1,5,6,7,9,9) 和sum 10
,说用mapping hashmap,面试管表示明白了。第二步,面试管提出实例中的整数可能
有重复,我提出用第二个hash map :intCountsMap,解释其记录整数出现的次数,以
及使用。他表示不很理解,然后要求coding。
// Write a method that takes in two parameters (an array of integers and an
integer x). Print out the pairs of integers in the array that sum to x.
List> getSumPairs(List array, Integer
sum){
//Collections.sort(array);
Map mapping=new HashMap();
Map intCountsMap=new HashMap();
List> res=new ArrayListInteger>>();
for(int i=0;iInteger n=array.get(i);
Integer target = mapping.get(n); //*** 这里在回答时 开始对了,
后来犯晕,n改成sum-n
if(target!=null){
//found:
Integer c=intCountsMap.get(target);
if(c>0){
res.add(new Pair(n,target));
intCountsMap.put(target,--c); //*** 这里,--c 笔误成c--
, 但是不知道考官会不会理解成知识点不牢
}
continue; //next item
}
Integer count=intCountsMap.get(n);
if(count==null){
intCountsMap.put(n,Integer.valueOf(1));
}else{
intCountsMap.put(n,++count); //*** 同样这里,++count 笔误成
count++ , 但是不知道考官会不会理解成知识点不牢
}
//Mapping: if count
if(target ==null){
mapping.put(sum-n, n);
}

}
return res;

}
avatar
g*i
2
他可能是想让你sort之后用two pointers做。
烙印你懂的。。。
avatar
x*y
3
这个面试管的期望答案,太难了点吧?
我一次的coding,就通过,很少。白板检查排错的能力也不强。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。