From Zero to Hero in Problem Solving
For every software engineer in the world, problem solving sounds like a monster that will haunt you for the rest of your career, and that’s kind of true to be honest, how can it not be while til this day, it is still one of the biggest standards (if not the biggest) used to evaluate candidates at almost 90% of tech companies, even at FAANG. if you happen to be the smartest engineer among your peers, you’d still have to excel your DSA (Data structures and algorithms) interview.
Therefore, software engineers tend to start training well for problem solving as early as possible in their careers, the more confident a candidate is in their DSA skills, the more opportunities they find knocking their door.
If you’ve heard this over and over again and decided to start training yet you have no idea where to start, grab your mug of tea, and let me take you through the journey of becoming an excellent problem solver.
Prerequisites
Pick a Programming Language
Whether you’re still in collage, or have been a software engineer for years, you will be asked about what language you prefer to use in interviews, hence you need to choose a language and explore it enough to be comfortable using it in problem solving, and by comfortable I mean knowing how to use the fundamental data structures and study the complexities of operating them. Most people prefer Python and Java given the fact that they might be the easiest to use, but if you’ve been writing C++ for a few years for instance and you feel comfortable with it, its not wise to decide to switch, this will cost you some time that you can invest in training instead.
Study Big O Notation
It’s rare to finish solving a problem in an interview and not hear the interviewer say “Okay, looks good, can we discuss the time and space complexity for this solution ?”. In fact, some interviewers might grade you down because you didn’t discuss the complexity of your solution on your own without being asked to. Chapter VI of Cracking the Coding Interview is a great resource to become well rounded in space and time complexities.
The Journey
You need to realize that problem solving is a skill you need to acquire, just like swimming, running, tennis, basketball or even turning the lights off by throwing flip flops on the light switch, you need to practice a lot in order to become good at it, you can’t wake up one day able to solve any interview problem because you solved 2Sum the day before. There are levels that you have to climb one by one in order to do that.
Level 1 : I wanna go home 😰
You might have solved some problems during your first year at collage trying to study the syntax of your first programming language, but you’ve never revisited doing that, and hearing “invert a binary tree” or “reverse a linked list” freaks you out, you’re reading a lot of titles; trees, lists, Dijkstra, heaps and you have no idea where to begin. Don’t worry, that’s completely fine, problem solving is a branching topic, in order to break this fear, you need to start somewhere that can give you a top view of what problem solving looks like. I personally would recommend:
And if you’re not really into reading books, I can recommend:
The previous resources are treasures, in fact, only reading those would get you ready to interview almost any small/medium sized companies. But that doesn’t mean you’re a daemon yet, you just have an overall imagination of the patterns of programming problems. Lists, arrays, multi pointers, graphs and so on, this is essential to help you categorize the problems you read instead of always trying to find a greedy random solution.
Level 2 : No thanks, I’ll Leetcode my way out.
It doesn’t freak you out to read a problem anymore and you don’t start sweating every time you hear the word “graph”, but it’s still challenging and it takes you some time to solve problems, you want to be more efficient at this. Leetcode.com might be the madison square garden of problem solving superstars, call me biased, Codeforces and Hackerrank are amazing yes, but Leetcode is a on a different league when it comes to fresh problem solvers. The categorization by difficulty and topics is excellent.
The way to start leetcoding is to study pattern by pattern, pick arrays for instance, solve 5 easy problem, 4 medium problems and 1 hard problem, next week, pick linked lists, do the same and so on until you cover as many patterns as you can. Don’t rush into solving hard problems immediately and don’t freak out if the people in the discussion section solve problems a lot better than you do, they have probably been solving problems long enough to feel confident posting their answers anyway.
Speaking of the discussion tab, NEVER skip visiting that tab after solving a problem (or if you don’t get lucky solving the problem). Always assume your peers in that tab know something that you don’t, if you learn on new trick every 5 visits to a discussion tab, you’ll find yourself progressing with a really fast and consistent momentum.
I would also suggest not spending more than 20 minutes on trying to figure out how to start solving the problem if you’re clueless, the objective is to cover as many patterns as possible, not to never fail solving any programming problem in the world. If you feel stuck, jump to the discussion tab without feeling guilty.
Level 3: Catch me if you can 🏃🏽♂️
At this stage, it is time to fix a major flaw in this plan, which is getting caught off guard. So far, you’ve been solving problems knowing what category you’re in, because you’ve been empowering your skills in specific areas, just like body builders work on their muscles selectively. You might solve a really hard DFS problem because you know it can be solved by DFS, but if you read it in a an online thread without any context it might get catastrophic. After all, interviewers and competitive programming problems don’t tell you what topics are related to the problems, you have to figure that on your own.
This is where you have to solve problems randomly, and there are many ways to do this.
- Filter Leetcode problems on a specific difficulty and select a random problem.
- Use the shuffle button on Leetcode which selects a completely random problem.
- Compete in weekly competitions, Leetcode has these every now and then, they usually consist of 4 problems that vary on level and topic.
Level 4: Need For Speed 🏎
Programming interviews and competitions have a challenge that might be as big as having the skill, and that is TIME, you’d usually have to solve 1–2 problems in an interview with somewhere near 45 minutes (including discussing the complexity), or you’d have a few hours to complete a set of problems in a programming competition. You might be able to solve any problem you see now, but sometimes (or usually) it takes you a generous amount of time to do so, this is where you realize you have to work on your timing. Muscle memory is an essential factor in timing, the more you flip a pan with an omelette the faster you can do it, and the more you implement a custom sort comparator that faster you can do it later, see what I did there ? 😉
Leetplug is a chrome extension that helps you with that, it can interact with Leetcode in order to indicate how much time you spend in each problem, using leetplug, constantly keep an eye on the timer and try to put yourself in a similar situation to feel more pressure and see how you’d perform, and bit by bit, you’ll get to operate fluently even if you know you only have 5 minutes remaining.
Level 5: Revise Revise Revise 📚
What used to freak me out the most is reading a problem I’m 100% percent sure I’ve solved before but I don’t know how to solve it again, if that happens to you as well, that’s ok, its the scourge of oblivion, while there might be a huge problem here which is that you’re memorizing solutions, yet still its not unexpected. To overcome that, revising older problems and patterns constantly is a great choice, there are multiple extensions out there that could help you with that. Don’t stop solving Linked List problems because you think you’re too good now, consistency is key.
At this stage, you’re ready to interview at any company in the world and not expect a DSA interview to have something you’ve never passed by before. Of course, there might be other topics you have to improve in based on your level such as system design.
Level 6: Call me Errichto 😎
Errichto is the reason I kept trying to improve myself no matter how good I thought I am in problem solving, every now and then, I would find him posting a video solving a really hard dynamic programming problem in less than 5 minutes. He is problem solving for a full time job basically, and the way he solves problems is just amazing, it is ok to not be like Errichto, after all, he’s been doing this for a really long time and is highly passionate about it. The reason I brought him up is because his youtube channel has many videos teaching you how to improve yourself yet even more and become a “redcoder”. He tends to touch on really advanced topics and tricks in problem solving that would help you shine among other problem solvers such as binary lifting and LCA etc.
In the end, it is essential to know that some developers ended up cracking their interviews and getting hired without having to go through the previous process, some people just have it in them. Some other people might disagree with the process above and thinks there’s a better way, if you’re one of them, why don’t you voice out your opinion in the comment section ?
Happy Coding !