How’s it going my lovely groovy subs,
Welcome to another edition of Math Mondays, where we cut through all the noise and focus on the most impactful theoretical knowledge to help you become a better developer and ace your interviews. Today, we’ll be talking about a simple identity that you must know: How do you calculate the sum of all integers from 1 to n?
It can show up in sneaky places. Not knowing it will mess you up in your coding interviews because you will add unneeded time complexity to your solution. Why solve something in linear time when you can do so in constant time?
The formula is pretty simple. For 1+2+…n the sum would be
n*(n+1)/2.
I’m linking a video going over the mathematical derivation. It’s pretty simple, so I would highly recommend watching it. The technique is pretty useful in a couple of different Math Contexts. Watch the following 3-minute video
For those of you that prefer more visual proof, here is another very quick video proving the concept.
I find that having multiple different ways of looking at the same thing can be very helpful.
Practice
Your next step is to practice this simple identity. You want to practice this till it gets ingrained into your memory. Till the formula becomes reflexive. Since this is a relatively simple concept, it won’t take long.
Making sure that it gets embedded into you will allow you to be able to use it in your interview. You will know that your prep is complete when you automatically remember the formula rather than doing the summation manually, regardless of the context.
To take it to the next level, practice a few variants of this summation. Here are a few to get you started:
Sum of all even/odd ints from 1 upto n.
Sum of Multiples of 5/7/your fav num till n.
Sum from 5/another number of your choice till n.
These will sharpen your problem-solving skills and get you familiar with the overall process.
That’s it for this week’s Math Monday. This is a simple idea but will be extremely beneficial to your performance.
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.
The Mathiest,
Devansh <3
To make sure you get the most of Math Mondays, 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