Dec. 25, 2016
Introduction
A few of facts about the algorithm:
1. In contest, spent over 10 hours to work on
2. The algorithm is advanced one
3. Score 8 out of 80
4. The algorithm is really a challenging one
5. Spent over 10 hours to work on after the contest, studied C# code
http://juliachencoding.blogspot.ca/search/label/array%20construction%20%28series%201%20of%205%29
Workout
1. Plan to write a code review request on stackexchange.com.
2. Need to study how to post a good code review on stackexchange.com
3. Be careful that do not get down vote, off-topic
4. Put down ideas why to ask code review
5. Julia also learned through the code review, how to write better English, her grammar mistakes.
Code Review Link
Case study:
http://meta.codereview.stackexchange.com/a/1035/123986
http://meta.codereview.stackexchange.com/users/11974/user1131146-account-abandoned
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Showing posts with label stack exchange: code review. Show all posts
Showing posts with label stack exchange: code review. Show all posts
Sunday, December 25, 2016
Monday, November 28, 2016
HackerRank - Bear and Steady Gene (VI)
Nov. 28, 2016
Julia noticed that those two blogs are most viewed:
http://juliachencoding.blogspot.ca/2016/03/hackerrank-bear-and-steady-gene_5.html
707 views
http://juliachencoding.blogspot.ca/2016/03/hackerrank-bear-and-steady-gene_13.html
699 views
So, Julia decided to review the algorithm, and she learned something new.
Summary of workout:
1. Find the most simple solution to study - two pointers, sliding window technique;
2. Write a C# version - understand the algorithm
3. Code review, and write a new version
4. Submit a code review request - her first coder review on stackexchange.com, and get some feedback.
Details:
1. Study the C++ code:
https://gist.github.com/jianminchen/c6b51207f9cc9b083573
Time complexity of algorithm: O(n)
typical two pointer technique, left/ right pointer, both at most travels forward once.
Timeout issue - O(n^2) brute force solution
2. Write a C# version:
https://gist.github.com/jianminchen/c4f1c84c984e58fdcdc467e6f28d84e3
code review:
1. line 26, int[] a = new int[1007];
1007 is not meaningful, we know the size should be bigger than 'Z', and we only need the array of size 4
2. variable i and index are not meaningful. There are two loops.
3. valid function from line 49 - line 58
line 52 - 55 - four constant chars are used.
3. Review the code and make the change:
https://gist.github.com/jianminchen/124b33e3d7aa0276e7b6ea4542c8ad5b
1. line 26 - 36, add 4 test cases, with 4 postcondition assertions
2. function name is changed to minChange
3. line 61, array of size 4 is declared instead of 1007
4. function indexOf() is added
5. variable names are changed, left, right, two pointers, move forward only
6. add two explanation variable c1, c2 to advoid complicated expression.
7. valid function is declared using a for loop.
Based on the code review on this post:
http://codereview.stackexchange.com/questions/142808/quick-sort-algorithm/142853#142853
answered by Eric Lippert
4. Submit the code review on stackexchange.com code review, here is the link:
http://codereview.stackexchange.com/questions/148407/hackerrank-bear-and-steady-gene
Review got from the site:
Actionable Items:
Julia likes to do some research, why it takes her over 6 years to start to work on stackoverflow, actively join the community, become one of them.
Some facts she put together here:
1. Julia noticed on Nov. 28, 2016 that on stackexchange.com code review section, the experienced professional responded to her first post in less than one hour; (a fact)
2. The advice she got is free, she does not need to pay; all she has to do is to share her question and her research; And the comments are very good; She also enjoys the sharing her workout.
3. Julia tries to get help from other professionals, she was too naive to check statistics of coding blog, but no one could give her any input. Finally, she figured out that she has to get smart, reach out stackexchange.com/ code review, ask help, show what she has completed.
4. Congratulate Julia to know how to connect with other peers efficiently, her first post on stackoverflow.com - her first 10 points of reputation.
5. Julia did some study on stackoverflow - how to ask a good question, and she knows that the question does not belong to her, it belongs to the community. That is the reason she can get help quickly. (her research on stackoverflow over 10 hours in Nov. 2016)
6. Write down her own understanding - research more later: Coding blog vs. stackoverflow contributions
June 6, 2017
Work on Leetcode 187 Repeated DNA Sequence
Julia noticed that those two blogs are most viewed:
http://juliachencoding.blogspot.ca/2016/03/hackerrank-bear-and-steady-gene_5.html
707 views
http://juliachencoding.blogspot.ca/2016/03/hackerrank-bear-and-steady-gene_13.html
699 views
So, Julia decided to review the algorithm, and she learned something new.
Summary of workout:
1. Find the most simple solution to study - two pointers, sliding window technique;
2. Write a C# version - understand the algorithm
3. Code review, and write a new version
4. Submit a code review request - her first coder review on stackexchange.com, and get some feedback.
Details:
1. Study the C++ code:
https://gist.github.com/jianminchen/c6b51207f9cc9b083573
Time complexity of algorithm: O(n)
typical two pointer technique, left/ right pointer, both at most travels forward once.
Timeout issue - O(n^2) brute force solution
2. Write a C# version:
https://gist.github.com/jianminchen/c4f1c84c984e58fdcdc467e6f28d84e3
code review:
1. line 26, int[] a = new int[1007];
1007 is not meaningful, we know the size should be bigger than 'Z', and we only need the array of size 4
2. variable i and index are not meaningful. There are two loops.
3. valid function from line 49 - line 58
line 52 - 55 - four constant chars are used.
3. Review the code and make the change:
https://gist.github.com/jianminchen/124b33e3d7aa0276e7b6ea4542c8ad5b
1. line 26 - 36, add 4 test cases, with 4 postcondition assertions
2. function name is changed to minChange
3. line 61, array of size 4 is declared instead of 1007
4. function indexOf() is added
5. variable names are changed, left, right, two pointers, move forward only
6. add two explanation variable c1, c2 to advoid complicated expression.
7. valid function is declared using a for loop.
Based on the code review on this post:
http://codereview.stackexchange.com/questions/142808/quick-sort-algorithm/142853#142853
answered by Eric Lippert
4. Submit the code review on stackexchange.com code review, here is the link:
http://codereview.stackexchange.com/questions/148407/hackerrank-bear-and-steady-gene
Review got from the site:
- In C#, method names should be PascalCased, not camelCased.
- In
minChange, you should use meaningful variable names fora,c,c2 - In
minChange, you can setvar ans = int.MaxValue, unless there is a compelling reason avoid usingInt32when you can useint, same withInt16vsshortorInt64vslong. - In
indexOf, you can use aconst string code = "ACGT";instead. This gives some compiler optimizations. - In
valid, (andminChange) you should use meaningful parameter names,nandadon't have any contextual meaning.
Actionable Items:
Julia likes to do some research, why it takes her over 6 years to start to work on stackoverflow, actively join the community, become one of them.
Some facts she put together here:
1. Julia noticed on Nov. 28, 2016 that on stackexchange.com code review section, the experienced professional responded to her first post in less than one hour; (a fact)
2. The advice she got is free, she does not need to pay; all she has to do is to share her question and her research; And the comments are very good; She also enjoys the sharing her workout.
3. Julia tries to get help from other professionals, she was too naive to check statistics of coding blog, but no one could give her any input. Finally, she figured out that she has to get smart, reach out stackexchange.com/ code review, ask help, show what she has completed.
4. Congratulate Julia to know how to connect with other peers efficiently, her first post on stackoverflow.com - her first 10 points of reputation.
5. Julia did some study on stackoverflow - how to ask a good question, and she knows that the question does not belong to her, it belongs to the community. That is the reason she can get help quickly. (her research on stackoverflow over 10 hours in Nov. 2016)
6. Write down her own understanding - research more later: Coding blog vs. stackoverflow contributions
Follow up
June 6, 2017
Work on Leetcode 187 Repeated DNA Sequence
Thursday, November 24, 2016
Stack Exchange: Code Review - Julia's new school
Nov. 24, 2016
Julia started her first day to look into stack exchange: code review, and then, she joined one of discussion - quicksort, she was amazed how she learned quickly in the place.
Her first reading starts from here:
http://codereview.stackexchange.com/questions/5648/any-way-to-make-this-recursive-function-better-faster/5661?newreg=7b2fea2453a54c15bc466355fea0891d
Learn from expert on code review:
http://codereview.stackexchange.com/questions/142808/quick-sort-algorithm/142853#142853
http://codereview.stackexchange.com/a/142853/123986
Julia also wrote a blog about quick sort in 2016:
http://juliachencoding.blogspot.ca/2016/02/quick-sort-practice-makes-difference.html
Julia's favorite reading:
http://codereview.stackexchange.com/questions/77782/quick-sort-implementation?rq=1
Study stackoverflow profile:
http://codereview.stackexchange.com/users/507/loki-astari
Actionable Items:
Read more live discussion on stackoverflow code review sections, at least find 5 top talents in C++, and find 10 advises from them in a week.
1. First one: Loki astari
Study stackoverflow profile:
http://codereview.stackexchange.com/users/507/loki-astari
Julia's favorite learning on Nov. 25, 2016:
So let the compiler work it out.
-- end of learning --
Coding Style - Great advice on coding/ design, a hackerRank question:
http://codereview.stackexchange.com/questions/140825/keeping-track-of-the-tennis-score/140827#140827
Julia started her first day to look into stack exchange: code review, and then, she joined one of discussion - quicksort, she was amazed how she learned quickly in the place.
Her first reading starts from here:
http://codereview.stackexchange.com/questions/5648/any-way-to-make-this-recursive-function-better-faster/5661?newreg=7b2fea2453a54c15bc466355fea0891d
Learn from expert on code review:
http://codereview.stackexchange.com/questions/142808/quick-sort-algorithm/142853#142853
http://codereview.stackexchange.com/a/142853/123986
Julia also wrote a blog about quick sort in 2016:
http://juliachencoding.blogspot.ca/2016/02/quick-sort-practice-makes-difference.html
Julia's favorite reading:
http://codereview.stackexchange.com/questions/77782/quick-sort-implementation?rq=1
Study stackoverflow profile:
http://codereview.stackexchange.com/users/507/loki-astari
Actionable Items:
Read more live discussion on stackoverflow code review sections, at least find 5 top talents in C++, and find 10 advises from them in a week.
1. First one: Loki astari
Study stackoverflow profile:
http://codereview.stackexchange.com/users/507/loki-astari
Julia's favorite learning on Nov. 25, 2016:
-- start learning:
http://codereview.stackexchange.com/a/77821/123986
-
Compilers Job
Don't do work the compiler can do for you:int arr[8] = {110, 5, 10,3 ,22, 100, 1, 23};
The compiler is better than you at it anyway and it will prevent
errors. Here you have said the number of elements is 8. As a human I
can't see that at a glance I could count them to verify but as a human I
am lazy and going to assume you got it correct. If you did not get it
correct then we will have problems.So let the compiler work it out.
int arr[] = {110, 5, 10,3 ,22, 100, 1, 23};
Now if the array changes size you only have to change one thing (the data). Rather than two things (data and size).-- end of learning --
Coding Style - Great advice on coding/ design, a hackerRank question:
http://codereview.stackexchange.com/questions/140825/keeping-track-of-the-tennis-score/140827#140827
Subscribe to:
Posts (Atom)