Showing posts with label easy level algorithm is the corner stone of problem solving. Show all posts
Showing posts with label easy level algorithm is the corner stone of problem solving. Show all posts

Friday, July 27, 2018

Leetcode 543: Diameter of binary tree

July 27, 2018

Introduction


It is an easy level tree algorithm. There is a linear solution O(N), the idea is to traverse the tree using preorder, and then calculate the maximum path value along the way. In the recursive call of maximum path value, all possible diameter can be calculated each step.


My practice


Here is my C# practice with optimal time complexity.

I had so many issues to work on the coding. I like to share the submission results and remind myself to be humble, and work hard on easy level algorithms first.


Ideally I should spend less than 10 minutes and submit once to get accepted. Here are highlights I had in more than one hour practice.

1. Line 34, global variable needs to reset. Online judge reported error one node tree return 3.
2. Line 52, 53, left and right variable should be used, but my mistake is to call the same function again. Time limit exceeded.
3. I aimed optimal time complexity solution, but the code has some issues...
4. I wrote time complexity O(N * N) solution, and then ...




Wednesday, July 18, 2018

Easy level algorithm as corner stone

July 18, 2018

Introduction


It is true that I only have submitted 100 algorithms on Leetcode.com. I have not fully used Leetcode online judge to train myself.

It is most profitable business to do next two weeks. Practice as many as easy level algorithms as possible.

Great advice 


I should try to write an easy level algorithm on Leetcode.com, 10 to 15 minutes each, try to write over 10 easy level algorithms as possible a day.

Advice from my favorite ex-coach who has submitted over 500 Leetcode algorithms this past Tuesday July 17, 2018. Those 35 minutes talk will bring me back to reality, stay grounded and reduce time to social chat, and mock interviews, and focus on coding.

Great thanks to those working hard with submission over 500 Leetcode algorithms. It shows the determination, hard working spirit.  I want to be one of them in short future. I need to set a target for 120 algorithms first, right now I have submitted 100 algorithm only.

Facts


As of July 19, 2018, solved 101/861, accepted submission: 759/511, Acceptance rate: 50.7% based on my Leetcode profile:
https://leetcode.com/jianminchen39/

Here is the graph to compare my ex-coach with me on Leetcode profile:




I like to call the coach mindset as a champion mindset. Prepare, prepare, get prepared early.