Advice a Beginner to Start Programming in This Way

Don’t worry if it doesn’t work right. If everything did, you’d be out of a job

Kirtipurohit
The Startup

--

Often when I’m solving problems, I don’t realize how fast time goes by and it's has been an hour I have been thinking and trying brute forces for my problem.

Don’t ever spend more than 15 mins thinking about a problem.

I have to keep in mind…

If you’re not able to come up with a solution within 1/2 hour or so - You don’t know how to solve it

Simple as that

Why you’re not able to solve a problem?

Either you’ve been living under a rock and have no idea, that there exists an algorithm to solve it in a particular manner or if you’re not motivated enough to solve it and therefore, your mind is roaming Italy! At the beginning of my coding days, I used to pick up a problem randomly and spend hours thinking and trying the same old shit

for i in range(n-1):
for j in range (i,n):
# Some shit
return count

And, as expected I failed every time and got a little frustrated, left the table, had some food, looked for my neighborhood crush, smiled, and stared a little, and then came back. ‘Alright Kirti, you know you can’t leave this’ and looked up for the solution

Now, I know that I can’t solve the problem no matter what happens and I need to look up to the solution.

and Booooomm !!! I realize that there something called dynamic Programming and you need to apply that and obviously, you need to get conceptually clear before applying a specific algorithm : ) and in this way, I ended up learning various algorithms and graph and trees concepts way before I got them in my computer science college course.

I ended up bunking 80% of my classes and still scoring 9/10. I was looked upon as a “made for computer science” student at that time. Yeah, I learned it the hard way which I’m proud of but there are some mistakes and key points I have to share with you, Obviously, this article is not about choosing the hard way or whether learning the hard way is good or not.

Well, I wouldn’t recommend it really, it’s not a bad idea but not a good one either. So the next time when a beginner asks for your advice make sure to include these points! Let’s get started.

#1 You need MATHEMATICS — It’s no choice

Why you need math for programming?

Well, 99% of the time you won’t need it but there’s a 1% chance that you might and it’s in those moments that separates a great programmer from the average ones. I’ve always ignored those questions which comprised of probability and discrete mathematics, thinking you really don’t. Thanks, to those youtube videos and my seniors claiming ‘you don’t need math but creativity’.

Sure, you need but apart from that math plays the most important role out there. Also, If you’re into machine learning or cryptography you’ll need mathematics and statistics.

#2 Don’t be shy to make notes

We all forget things, right? A question you asked on StackOverflow months ago has received another answer today you check out that question and wonder …really?

Was it me who asked this question? but why does it look so unfamiliar to me?

Usually, when I’m attending LeetCode contests there are 4 questions that try to cover a variety of concepts based on different algorithms and data structures, and math as well. It happens that I know how to solve a problem, which domain does it belong to but I totally forget the algorithm or an efficient approach and end up spending a lot of time thinking, getting frustrated, and eventually giving up.

Sorry for the handwriting!

I started making notes of the problems which I wasn’t able to solve or can be overpassed. This mostly consisted of dynamic programming , trees and math problems. You don’t need to specify the problem statement much or the solution as well.

Just a hint or the formula is enough.

Sorry for the handwriting!

Your brain loves visualizations! It remembers visuals and diagrams more profoundly therefore, make sure to create a diagram because it can hit your memory instantly reminding you of the answer you’ve been looking for. This also helps when you’re attempting a similar problem, maybe in a contest or interview ; )

#3 Copy the algorithm, not the Code

It’s totally alright if you can’t solve the problem or have to look up to the solution. It’s doesn’t signify your potential. What matters the most is how you learn from your mistakes.

When I’m done with trying brute forces and enough of thinking and testing is done I finally, go for a solution. I get the feeling that I’ve had enough, I’ve done a lot of work and mentally feeling secured and safe that yeah, I did try — Sure, I have but this is where I always commit a mistake of directly looking at the code and getting the ‘Ahhh…!!’ satisfaction instead, of checking the algorithm once mentioned in the editorial. Now, I’ve totally ignored my past mistakes and go for the one that received the highest votes and views. I trace the code on a paper, understand it, and code in my favorite language(python )

My code looks perfect now, A perfect one-liner python code —

source

Where did I go wrong?

Instead of improving my code, I worked on a new code- completely discarding the old one. No, no, no, don’t do that.

My code looks perfect but I felt that this isn’t mine. Sure, I have tried a lot but deep down I feel like …

Look, this may seem normal but it isn’t, in the long run, it really isn’t okay.

What I learned from those top-coders is that they try various approaches and their practice is what makes them come up with a sexy one-liner.

Later after months when I felt that I really wasn’t growing in competitive programming I promised myself not to look at the code first but, follow the algorithm.

Trace the algorithm.

Code in my way and that’s what I’m gonna submit

Since I’m learning python I always try to code in python but C++ is something I’m fluent at. I swore that if I’m able to do it in python I’ll go for C++ and check for python later.

Note your mistakes down.

Note the key points you missed.

Not on your iPad or OneNote but, a book.

It might be boring at first, but you’ll fall in love with your competitive programming book ; )

Thank me later!

--

--

Kirtipurohit
The Startup

Programmer | Technical content Writer | Lives in India | Wanna go where I can breathe freedom