DEV Community

Cover image for A 4-Hour Problem Solving Experience from Leet Code
Aung Myo Htet
Aung Myo Htet

Posted on

A 4-Hour Problem Solving Experience from Leet Code

Problem-solving is a well-known aspect of computer science or coding in general, and there’s even a sport called competitive programming (CP), dedicated to it. So before moving on with coding, a little bit about my background: I am a mechatronics engineering graduate from Southeast Asia with the interest of developing software solutions for real-world problems.

Throughout my college years, I had been in and out of programming but I wasn’t really in the environment of a structured computer science community, either offline or online. As a result, my experience with programming was just writing multiple lines of code to get an output, and I was totally oblivious of the nuances and intricacies of writing a program. I wasn’t even aware of the existence of data structure and algorithm.

Until recently, since the beginning of 2020, I have started to realize the gaps in my foundational knowledge of programming, and been trying to fill those gaps. More specifically I have begun to pay attention to DSA (data structure and algorithm) and to test out the knowledge I have gained, I have been trying to engage in Leetcode problem sets. Initially, I started with the easy ones which were somewhat challenging to an extend. I began solving problems with medium difficultly a few days back, and the first one I picked up was quite demanding for my level. Here’s the description of the problem set.

Alt Text

Initially, it was uncomplicated in terms of setting up the problem — mapping the input digits into letters sequence. For example, if the input digit is 23 as in the example, two arrays of letters would be generated ['a','b','c'] and ['d', 'e', 'f']. So the challenge was to generate an array with all possible letter combinations by using these two arrays. It got to me instantly that by utilizing nested for loops, I was able to generate the output the same as the one in the above picture though it would have the time complexity of 0(n²).

It all happened within half an hour, and I was over the moon. However, upon submission, the solution got rejected, and as a result, I got into the testing and debugging process. It turns out that my solution did not work for the inputs of more than two numbers. I started out attempting the problem at 7 pm, and now I was at around 7:45 pm. Until around 9 pm, I was sketching out different ideas and algorithms in my notepad hoping to solve the problem within that particular day. Finally, to a certain point after multiple attempts, I felt this problem set was out of my scope, and I wasn’t eligible for that. With a minute fraction of confidence, I went to bed with a miserable mood.

On the next day morning, I reattempted the problem with a tiny spark of hope, but this time, I was consciously trying to utilize the knowledge I had gained from data structure and algorithm. And eventually, within an hour, I was able to see what I was missing and came up with a feasible, efficient solution.

Alt Text

To be honest, this problem or this particular scenario might be a piece of cake for some of you reading this, but in my case, I had to struggle to get it completed. This experience is truly special for me since this is my very first moment of realizing the quality of perseverance and self-confidence. To conclude, whatever you are learning right now regardless of the subject, just try to utilize the knowledge you have acquired to something tangible, rather than being in the endless loop of learning something without applying it anywhere. Good luck and happy learning!

Cover Photo by Tim Gouw on Unsplash

Top comments (0)