How to Solve Leetcode Brain Teasers [Technique Tusdays]
How you can solve the tricky interview questions that feel like they were designed to mess with you.
To learn more about the newsletter, check our detailed About Page + FAQs
To help me understand you better, please fill out this anonymous, 2-min survey. If you liked this post, make sure you hit the heart icon in this email.
Recommend this publication to Substack over here
Take the next step by subscribing here
We’ve all been there,
You’ve prepped all the Leetcode theory. You can code up complex graph traversal problems, and know all about Dynamic Programming Patterns.
And then you are given a seemingly simple problem in your interviews. No confusing wording, complex test cases, or messy backtracking. You rejoice and start working on it, only to hit a wall. You understand the problem, but you can’t figure out what to do to create a solution. You, my friend, have been hit by a brain teaser. Brain Teasers are a kind of problem with a relatively simple premise. There won’t be any hidden data structures, complex coding, or the requirement to know anything extremely high level. The reason they are hard is their simplicity- since the information seems very obvious, it’s hard to know how to use it to proceed.
The below problem is a great example of such problems. You can solve it by simply reversing the inputs and brute-forcing the string multiplication, but this is slow. The better solution is not hard to code but it does require some creativity.
In this email/post I will tell you can beat these kinds of problems.
Key Highlights
Why Brain Teasers are hard- If we had to compare Coding Interview Leetcode Problems to rock climbing, typical Leetcode problems are like a very rough, tall, and steep rock. Climbing this kind of rock requires skill, strength, and recognition but there will be multiple avenues you can attack, and use to build yourself up. Brain Teasers on the other hand are smooth and small. Not intimidating to look at, but you will find yourself stuck on what to do next. Here are some steps you can use to solve these kinds of problems.
Look for what you’re familiar with- If you’re stuck and can’t figure out what your next steps should be, start grasping for straws. Look at the question, and try to see if you can find anything you are familiar with. Can be an idea, process, or algo. Going the familiar thing will allow you to have a foothold in the overall solution to the problem. In the above problem, the most obvious idea we latched onto was multiplication.
Analyze the process in-depth- Once you have an idea you can latch onto, start analyzing it in depth. To come up with the solution to the problem, I broke multiplication down into its basic form. This gives you more clarity on avenues that you can attack. By breaking the process of multiplication down, I got a much better idea of how I could compute the solution without directly converting the inputs into ints.
Start Talking loudly- If nothing else works, start talking. Talk about where you’re stuck, what you’d need to get unstuck, how that could possibly be accomplished etc. This is similar to the Rubber Duck Method, which I covered in this post. This works because talking out loud forces your brain to make connections more explicit as you have to articulate things. This is a great way to expose all the ‘leaps’ your mind makes and allows you to think better. This Harvard article is a great example of how talking out loud can help with learning.
Start implementing these tips, and you’ll be shocked by how many of these kinds of problems you’re able to solve. Obviously, the very tricky questions will still require some understanding of Data Structures and Algorithms along with the coding. Make sure you keep those sharp so that you have more tools in your tool belt.
I created Technology Interviews Made Simple using new techniques discovered through tutoring multiple people into top tech firms. The newsletter is designed to help you succeed, saving you from hours wasted on the Leetcode grind. I have a 100% satisfaction policy, so you can try it out at no risk to you. You can read the FAQs and find out more here. Use the button below to get 20% off for upto a whole year.
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. 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
I see you living the dream.
Go kill all and Stay Woke,
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 Machine Learning breakdowns: 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