Phone Interview L

Today is my first phone interview since I start to look for jobs. I feel so nerves before the clock run to 10:00 am. Actually, zzz and I go through the interview question till Midnight at two o‘clock.

My phone interviewer is a mixed race girl, I think that she must have Chinese descent. Her accent is perfect, I can understand her meaning clearly.

Firstly, she talked about her jobs at LinkedIn, what she does, what she teams do. I didn‘t catch up all the things she said.

Then, she let me said my background. Do not feel nervous, it is just a warm up.

Thirdly, she gives me a smoke test problem let me solve it. There are two problems: Two Sum,   Shortest Word distance

Two Sum.

This is a classical problem in Leetcode. The problem same as the word "abandon" in CET-6. Each programmer starts to find a job, they all need to solve problems on LeetCode OJ.

But this one is an upgrade one. Here is a good blog write about this problem. Thanks for grandyang, his LeetCode blog is so helpful, he shares the LeetCode premium problems.

After I give her an O(n) / test(), O(1) / store() solution, she want me to implement another one. O(1) / test(), O(?) not matter / store. What I need to do is pre process the input when store() it.

http://www.cnblogs.com/grandyang/p/5184143.html

Some hints:

  1. When she let me go through my code, my thought is not so clear. And not working at all. so said the wrong test answer.  Calm Down.

When she argues me that the first solution, line9, I should go through the code carefully because my code has no bug, the hint she gives will cause bugs.

  if (second == p.first) return p.second >= 2;
 1 class TwoSum {  //O(n) / test()   O(1) / store() 
 2     void store(int input) {  // time complexity O(1)
 3         numbers[input]++;
 4     }
 5     bool test(int input) {   // time complexity O(n)
 6         if (numbers.size() == 0) return false;
 7         for(auto p : numbers){
 8             int second = input - p.first;
 9             if (second == p.first) return p.second >= 2;
10             if (numbers.find(second) != numbers.end()) {
11                 return true;
12             }
13         }
14         return false;
15     }
16     unordered_map<int, int> numbers;
17 };
 1 class TwoSum {  //  O(1) / test()
 2     void store(int input) {
 3         for(auto n : numbers) {
 4             sum.insert(input + n);
 5         }
 6         numbers.push_back(input);
 7     }
 8     bool test(int input) {
 9         if (sum.empty()) return false;
10         return sum.find(input) != sum.end();
11     }
12     unordered_set<int> sum;
13     vetor<int> numbers;
14 }; 

WordDistanceFinder

/* This class will be given a list of words (such as might be tokenized
* from a paragraph of text), and will provide a method that takes two
* words and returns the shortest distance (in words) between those two
* words in the provided text.
* Example:
* WordDistanceFinder finder = new WordDistanceFinder(Arrays.asList("the", "quick", "brown", "fox", "quick"));
* assert(finder.distance("fox", "the") == 3);
* assert(finder.distance("quick", "fox") == 1);
*
* "quick" appears twice in the input. There are two possible distance values for "quick" and "fox":
* (3 - 1) = 2 and (4 - 3) = 1.
* Since we have to return the shortest distance between the two words we return 1.
*/

// wordOne == wordTwo -> 0
// word does not exist -> -1

Not bug-Free.  The interviewer found a bug in my code.

 1 class WordDistanceFinder {
 2 public:
 3   WorddistanceFinder(vector<string>& wordsList) {
 4     for(int i = 0; i < wordsList.size(); i++) {
 5             words[wordsList[i]].push_back(i);
 6     }
 7   }
 8   int distance(string wordOne, string wordTwo) {
 9       if (wordOne.size() == 0 || wordTwo.size() == 0) return -1;
10       //if (wordOne == wordTwo) return 0;  bug
11       const vector<int> &v1 = words[wordOne];
12       const vector<int> &v2 = words[wordTwo];
13       if (v1.empty() || v2.empty()) return -1;
14       if (wordOne == wordTwo) return 0;  // shoud check wordOne == wordTwo at here.
15       int p = 0, q = 0;
16       int ret = INT_MAX;
17       while(p < v1.size() && q < v2.size()) {
18           ret = min(ret, abs(v1[p] - v2[q]));
19           if (v1[p] < v2[q]) p++;
20           else q++;
21         }
22       return ret;
23   }
24 private:
25   unordered_map<string, vector<int>> words;
26 }

That‘s all my first technical interview. Hope I pass it and move on to onsite.

时间: 2024-10-15 19:33:03

Phone Interview L的相关文章

百度好几个市房管局开始开发了开始

http://www.ebay.com/cln/yi_ch32/book/167329925017/20150205 http://www.ebay.com/cln/gozh754/book/167427188010/20150205 http://www.ebay.com/cln/guamyz-peuhck/book/167535329016/20150205 http://www.ebay.com/cln/nito098/book/167427189010/20150205 http://w

卷积神经网络和CIFAR-10:Yann LeCun专访 Convolutional Nets and CIFAR-10: An Interview with Yann LeCun

Recently Kaggle hosted a competition on the CIFAR-10 dataset. The CIFAR-10 dataset consists of 60k 32x32 colour images in 10 classes. This dataset was collected by AlexKrizhevsky, Vinod Nair, and Geoffrey Hinton. Many contestants used convolutional n

What Great .NET Developers Ought To Know (More .NET Interview Questions)

A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with about half the folks saying I was nuts and that it was a list of trivia. The others said basically "Ya, those are good. I'd probably have to look a few

安卓面试题 Android interview questions

安卓面试题 Android interview questions 作者:韩梦飞沙 ?2017?年?7?月?3?日,??14:52:44 1.      要做一个尽可能流畅的ListView,你平时在工作中如何进行优化的? ①Item布局,层级越少越好,使用hierarchyview工具查看优化. ②复用convertView ③使用ViewHolder ④item中有图片时,异步加载 ⑤快速滑动时,不加载图片 ⑥item中有图片时,应对图片进行适当压缩 ⑦实现数据的分页加载 2.      对

JULIA BOORSTIN — Interview a Broadcaster!

JULIA BOORSTIN — Interview a Broadcaster! Share Tweet Share Tagged With: Interview a Broadcaster Study conversational English in this interview with NBC Broadcaster Julia Boorstin. See how even professionals use reductions and contractions all the ti

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

gcc -l参数和-L参数

-l参数就是用来指定程序要链接的库,-l参数紧接着就是库名,那么库名跟真正的库文件名有什么关系呢?就拿数学库来说,他的库名是m,他的库文件名是libm.so,很容易看出,把库文件名的头lib和尾.so去掉就是库名了 好了现在我们知道怎么得到库名,当我们自已要用到一个第三方提供的库名字libtest.so,那么我们只要把libtest.so拷贝到/usr/lib里,编译时加上-ltest参数,我们就能用上libtest.so库了(当然要用libtest.so库里的函数,我们还需要与libtest.

【BZOJ2741】【块状链表+可持久化trie】FOTILE模拟赛L

Description FOTILE得到了一个长为N的序列A,为了拯救地球,他希望知道某些区间内的最大的连续XOR和. 即对于一个询问,你需要求出max(Ai xor Ai+1 xor Ai+2 ... xor Aj),其中l<=i<=j<=r. 为了体现在线操作,对于一个询问(x,y): l = min ( ((x+lastans) mod N)+1 , ((y+lastans) mod N)+1 ).r = max ( ((x+lastans) mod N)+1 , ((y+last

mppe +H -M +S -L -D -C中个字母意思

mppe +H -M +S -L -D -C what each character mean. 根据Microsoft Point-To-Point Encryption (MPPE) Protocol的rfc3078文件中第2节Configuration Option Format: H:使用stateless模式(this indicates that the sender wishes to negotiate the use of stateless mode) M:使用56bit密钥