Monday, March 5, 2018

Four sum algorithm

March 5, 2018

Introduction


It is the classical algorithm n-sum algorithm, n is four. I met a peer the second time, and he advised me that I should work on a small test case when I work on the algorithm. So it is much easy for the peer to understand me and my idea to solve the algorithm.

Algorithm practice


Here is my C# practice.

The peer asked me the question on the code of line 30, what if item[0] < second? that is a very good questions. I gave some explanation, but after the mock interview, I thought about carefully.

False argument:

Since first two numbers are selected in brute force ways, so it is impossible. Otherwise the numbers are already found and return statement will terminate the double for loops already.

It is not true. Here is the counter example I ran through the platform:

[1, 2, 3, 4, 5, 9, 19, 12, 12, 19], sum is 40

The program will find [3, 9, 9, 19], but it should be [4, 5, 12, 19].

Actionable Items



It is the second time I met the peer. Originally we plan to have a meetup this coming Wednesday as well. I prepared a meetup plan, here it is.

I also learn how to catch up everything I need to work with different talent. Every time I work with different talent, I understand that it is most important to focus on foundation of computer science and algorithm.

No comments:

Post a Comment