Sunday, December 17, 2017

Code review is fun

Dec. 17, 2017

Introduction


I spent 10 minutes to review the algorithm written in C++ after I spent over one hour to write a  C# version of Leetcode 4: Median of two sorted array. The code in C++ is based on the work I presented and the peer made some simplification in C++.

I like to give a quick and short code review.

Code review for fun 


Here is the C# code I wrote.

Here is the C++ code I like to review.


A variable written in r on line 9 can be understood using multiple meanings, it can last index of the array, or it can be the length of the array, and interview is kind of competitive programming, under pressure you will confuse yourself as well, time is limited to 30 minutes. So if you write something which is verbose, it is good and it is self-explanation. 

Of course, coding style can be picked up in less than a few hours, as long as the algorithm is correct you should be ok. Most important is the strength of algorithm analysis itself. But you certainly should ask the interviewer his/ her style. 

FindIthElement -> FindKthSmallestElement, if it is private function, then in C# starting from lowercase. The function name should be called findKthSmallestElementThroughTwoSortedArray, the name covers every detail of function arguments. And also one more thing is missing in the title, it should be called findKthSmallestElementThroughTwoSortedArrayWithGivenStartIndexes. 

Do not laugh at me. I am just acting like a teacher, or an interviewer. 



No comments:

Post a Comment