Solving Coding Problems through Case by Case Analysis of Input[Technique Tuesdays]
This will help you a lot with the proofs and designing large scale solutions
Hello hello,
Today I will share with you a deceptively powerful technique to really boost your problem-solving. It’s one of those techniques that are extremely simple, so they often blend into the background. Nevertheless, without this technique, I would have a hard time coming up with solutions in a clear and efficient way.
OG readers will know how much I love this technique since it shows up in a lot during our solutions. This magic technique is the mighty case-by-case analysis. What does this mean? Let’s cover that.
Highlights
This post will cover the following-
What is it- Simply put, we will take a problem and split it into different cases. This is typically done by analyzing the domain of inputs to our problem and spotting how each of these could be solved.
How to get good at it- You probably already are. All we need to do is get you used to this. Comes from practice. That’s why we this newsletter/my coaching.
Sound exciting? Let’s get into it.
Splitting things into cases
Some of you might be a little confused by what I meant by the statement, “we will take a problem and split it into different cases”. Let me elaborate on that statement.
You know how in Software Engineering, people talk about how we should break our problems into easier sub problems and solve them? That is exactly what we do here. We take our complex input/problem and look at how we can carve it into easier subproblems. This is done by analyzing the input and breaking it into the kinds of input we can recieve. Then we try to solve for the individual different cases. For example, if we were solving a problem over integers, we might benefit from solving the problem for even and odd numbers respectively and trying to combine the results.
This technique is something I use a lot. In fact, last week’s solution used this to figure out the details of the optimal solution. Take a look below for another example of how I used this technique.
Go through other solutions I have posted here. You will see that I rely on this technique quite a bit. I like it for many reasons-
I get to pick the low-hanging fruit by solving the easier cases. This was the reason I started using this technique.
Gives me a clear next step instead of getting stuck. Remember awkward silences are a death sentence in your interviews.
Easier cases can provide you hints on harder ones. This makes it better for solving problems, as opposed to trying to solve everything at once.
It looks really neat and logical. That’s because it is.
This might seem like I’m overhyping a simple thing, but this is something that many of my students and premium subs were able to use with great success.
Getting Good at this
So how can you get good at this technique? Short answer, practice. This is one of those techniques that can be implemented in a lot of Leetcode questions so that is a pretty clear avenue. Using this kind of analysis in your normal projects will be extremely helpful as well.
I became familiar with this technique through Math. Many Geometry, Theoretical Computer Science and Algebra proofs use this technique. I thought it felt like cheating at first, but it has been a game changer. People looking to be more advanced might benefit from implementing this approach in those subjects.
Before proceeding, if you have enjoyed this post so far, please make sure you like it (the little heart button in the email/post). I also have a special request for you.
***Special Request***
This newsletter has received a lot of love. If you haven’t already, I would really appreciate it if you could take 5 seconds to let Substack know that they should feature this publication on their pages. This will allow more people to see the newsletter.
There is a simple form in Substack that you can fill up for it. Here it is. Thank you.
https://docs.google.com/forms/d/e/1FAIpQLScs-yyToUvWUXIUuIfxz17dmZfzpNp5g7Gw7JUgzbFEhSxsvw/viewform
To get your Substack URL, follow the following steps-
Open - https://substack.com/
If you haven’t already, log in with your email.
In the top right corner, you will see your icon. Click on it. You will see the drop-down. Click on your name/profile. That will show you the link.
You will be redirected to your URL. Please put that in to the survey. Appreciate your help.
In the comments below, share what topic you want to focus on next. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
Happy Prep. I’ll see you at your dream job.
Go kill all you magnificent maestro,
Devansh <3
To make sure you get the most out of Technique Tuesdays, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75