Saturday, August 4, 2018

How to break the ice on algorithm problem solving?

August 4, 2018


Introduction


It is the first ten minutes and then I have chance to break the ice with the interviewer and get warm up the algorithm I have to work on. Since it is top ranking software companies, usually the first one is hard level. How to break the ice? I like to write something related to this topic.

One idea


I like to promote the idea to enumerate what variables in the problem, and how many possible time complexities for the solution? Which is optimal one? How can we lower down? Do we have limitation of time and space complexity? What is upper bound?

One algorithm as an example


Let us give the algorithm called "write an iterator for list of iterator with HasNext and Next two methods interface". We can denote that there are n list, maximum length of lists is m, and then let us try to use those variables to define Hasnext, Next time complexity. What should we target for the optimal one?


Stay open


It is much better to stay open when I have to write some code. Even if I do not know what I should write, I just ask one more question before I write the code. I have to give myself last chance to clarify the problem. I always forget to use data structure, extra space to exchange time for optimal time complexity. Queue, stack, heap or binary tree, what ever. It is always to scan through the list and find one to apply.

Do not write code until you have an idea how to solve the problem? I should say that please wait one more minute to let me think about the idea.

Do not be shy, and just say it. And also say that do not worry. The idea is more important compared to write the code.

Do check the time. First algorithm I should have at least twenty minutes. I will have time to write if I come out the good ideas.

Tell the interviewer I will have this structure. Go over keywords, and then write down what is asking. And then go over possible time complexity. And then brainstorm the ideas to solve the problem.

It will take a few more minutes but it is necessary in order to find the optimal solution. No rush to write the code.


No comments:

Post a Comment