He welcomed me and introduced himself and told me there will be two questions. It was short and he got directly to the first question. It was a problem and it took me some time trying to understand and analyze the question especially the input and output. I was quickly able to find the brute force solution of O(n2). Being used to TopCoder and small input, no need for other data structure when the input won’t exceed 50 so I thought of this solution at first and it took me some time till I was able to try to think smarter – mistake 1. He asked me to code the solution I have just said using any programming language – don’t he considered C# one. He said he prefers C++ or Java as they use those languages in most of the projects in Google. I was told that I have two bugs. One of them was forgetting first initialization of a variable and the second one was writing = instead of == in an if statement.
He asked me if there was a better solution, I started to think again and try to get out of the box which I stuck myself in – mistake 2. I thought of a solution which involves sorting and then binary search leading to complexity O(nlog2n).
He said that it could be solved in linear time. I thought that it might be represented by a linked list. Then he told me what about using a hashmap. I got it by then, but it was obviously too late. Then he asked about what the key would represent, I answered that. He asked me how to write that using C++, I wrote the mapping but not in the exact syntax – mistake 3.