Tuesday, December 25, 2018

LeetCode - completed easy level problems

LeetCode is one of the popular coding practice online sites. One can find coding interview questions from big IT / financial companies, and submit their code for each questions to compare code performance against statistics from thousands of other coders. As of this writing there are 957 problems available; easy / medium / hard difficulty being roughly one third respectively. In order for the submitted code to be accepted, it has to pass all (as many as hundreds) test cases of varying length and complexity, within reasonable amount time. One will see 'time limit exceeded (TLE)' error if not. So solving a problem means [1] implementing [2] efficient algorithm.

Earlier this year I started Python coding practice with LeetCode. Back then with rudimentary coding skills I managed to solve a few easiest problems after fixing the code many times due to TLE. It was so annoying to have my code denied by invincible extreme test cases. So I gave up within a few weeks. I switched to a far more interesting challenge site - Project Euler. LeetCode has primarily computer science style problems, whereas PE heavily involves mathematics which I like. I learned a lot about basics of Python by comparing my PE code with others. After about 4 months of serious dedication into Project Euler with Python (I will write about this later) I retried LeetCode. The problems now seemed far easier. A lot of codes I wrote for easier problems passed all test cases pretty quick. What a surprising improvement.

Then I switched back to LeetCode. Time permitting, I could solve 10 problems within 3~4 hours in one shot, even including the time spent on examining code by other people for subsequent study, and on recording the code and notes (I have most of the codes saved on my Gmail account)! Furthermore, easy level problems felt too easy thus not worth wasting my time and effort. But I decided to be a bit patient. I wanted to cover all major topics and to learn basic code snippets particularly because I am not a computer science major. 

I solved the easy problems one by one with increasing difficulty. Toward the end the problems were getting hard, so recently I could solve only a few per day. And today, on X-mas 2018 (not what I intended), at last I completed all ~240 easy problems available free (about 10% of problems are open to paid premium users, which I plan to solve later all together).


Through the journey I could self-study crucial topics such as array / string / hashing / dynamic programming / binary tree / etc. Out of the key areas, depth first traversing binary trees using recursive algorithm was the hardest to get used to since it requires a highly distinct mode of reasoning. Now that I successfully went through tens of simple examples by myself, I am afraid no more of writing recursive code blocks, while I definitely was in the past. Truly a big step forward.

In LeetCode, you can see other's code in the discussion board for each problem without having your code accepted. But I would like to emphasize that there were less than ~5 cases out of ~240 problems where I did that. Those were mostly when the problem description was unclear, for which a lot of users had strong complaints. Except for those, I am proud of myself finishing easy problems all by myself.

Now I am walking into medium level problems. Hope I don't give up until I finish all of them, and post the news in the near future.

No comments:

Post a Comment

Philips SAECO Xsmall espresso machine repaired

I have a SAECO Xsmall espresso machine. I bought it in Dec 2014, and brewed 2~3 cups of espresso per day on the average over the last 6 year...