Showing posts with label being interviewee. Show all posts
Showing posts with label being interviewee. Show all posts

Sunday, March 25, 2018

Island count

March 25, 2018

Introduction


It is my mock interview algorithm called Island count. I was so excited to work with a peer who is from Israel this morning 10:00 AM. The peer told me that it is better to write an iterative solution.

Code review


I had to follow the advise from the peer, and then I decided to write a queue to apply breadth first search to visit neighbors, mark visited.

Here is my C# code passing all test cases.

The instruction to play mock interview nicely


I have worked on this algorithm so many times. I know how to train myself one more time nice and easy, get more experience how to write readable code, practice one more time to explain the algorithm and talk about ideas with a peer.

First few minutes, I will write down the matrix using example 5 x 5 matrix, and go over row by row from left to right starting from position (0, 0). If I find the first one, I will mark it visited, and then use DFS/ BFS to visit all neighbors as elements in the same island. I will increment island count variable one. I will mark the first island using char 'A', next island using 'B', likewise. I will apply the same analysis twice, using -1 to mark first two islands A and B, and then just quickly apply C, D, E, F for the rest of islands.

After that, I will ask the peer's advice to choose DFS or BFS. Give him/ her a choice, and follow  the advice. I am willing to write any solution, but I do not want to stick on one solution, I like to practice any solution if need.

This time the peer told me that I should not use recursive function, it is written to write iterative solution in mock interview platform for interviewer. So I have to follow the advice, decide to write the iterative solution.

I thought about using for loops, and then decided to write a queue. Since it is the only way I can apply BFS without using recursive function, otherwise I cannot handle the neighbors just using loops. Data structure queue is definitely needed.

Beautiful code


It is not tough for me to write readable code using Queue, and apply BFS algorithm. I have practiced similar algorithm so many times last 12 months.

I learn how to write readable code last 18 months.

Give credit to the code reviewer, here is the link.

Here is the blog about my past practice. I need to get organized and then I can review what each my past practice and see how good I am getting.


Sunday, January 28, 2018

Four Sum problem

January 28, 2018


Introduction


It is busy weekend. Today I had a mock interview at 4:00 pm,  I felt that I were a student to be interviewed for an algorithm, the teacher is questioning me everything, and make sure that I understand everything I write.

Code review 


Here is the code.

Highlights of interview:

1. First the data type of function on line 44, getTwoSum, its return type dictionary's key is integer, not string;
2. Second, the array should be sorted in ascending order. I forgot to write the first round.
3. Discussion of dictionary search algorithm time efficiency.



Sunday, January 21, 2018

4 sum algorithm

January 21, 2018

Introduction


It is the most popular algorithm and also my favorite one. I asked Four sum algorithm mock interview practice on the code review two months ago on stackexchange.com. This time I had to write the algorithm in mock interview at 12:00 PM mock interview, I found that it is easy to write and also I finished the analysis and coding in 30 minutes.

Code review


Here is C# code with the analysis.