How to tackle algorithms that starts to be mathematical when you do not have a math a background

I have been practicing algorithms on coding sites like codewars and started to encounter algorithms that are mathematical like math symbols on some questions from changing to binary bits or Pascal triangle (mostly the kyu 4-5 questions) and I am unsure how to approach them better.

Aside from questions that involve arithmetic operations, I find myself limited in solving questions that are math intuitive and have difficulty understanding the question. My level of maths is algebra 1 ish as I haven’t touched maths for almost 8 years.

For anyone who struggles with the mathetical algorithm, problem sets what would your approach be when encountering such a problem? also, would it be practical to actually pick up maths again from algebra 1 to maybe calculus level?

I did consider picking up maths again. Personally i do not hate maths , but i struggle to find the time commitment for it. I feel if i wanna learn maths i need like 6 months commitment minimum and have to push in time for it aside from practicing coding itself which dosent seem practical.

Hope to seek some advice !

Binary is an important thing to know in Programming, I don’t for interviews, so you may want to check on some things of math

The more advanced math is situational, for example you would need calculus and trigonometry if you entered the field of simulations or advanced animations but don’t need it for web development

I would say maybe some math could be useful to review - for example, do you know Khan Academy? They have free courses in a lot of subjects, maths included

A computer science course would also touch on the maths needed

i do know about binary but i am v slow in converting in my hand , i took classes related to OS and networking before just the problem sets needed me to convert numbers which i have to repeatedly look up how its done again.

i have attempted khan academy for algebra 1 but v slow way to work way up to advanced maths. Im not sure if its practical to go thru the entire section from algebra 1 to calculus just to solve algorithms which is why im asking.

Typically i am looking for areas to focus on which are common in interview questions , as well as practical maths that are useful for programming like discrete maths and whether they need preresquite maths to learn them.

In practice you won’t need much math beyond what you know. The examples you’re looking at are slightly misleading because they’re often written to be tricksy. Codewars in particular seems to have a high percentage of problems written by people with a math background (or who have found a math trick and then applied it as a problem). In a sense I think they’re trying to look clever.

This isn’t to say that math knowledge isn’t important, it’s just that in practice it only becomes important when you work on things that really need it (graphics is the obvious case). For the leetcode-style algorithm challenges, there are many that will have some simple mathematical trick that, if you know it, allows you reduce some loops down to a single equation. A good example is on FCC – there is an challenge where you’re asked to sum all numbers in a range. This has a mathematical solution, where you take the first and last value, plug it into an equation, and it gives you the answer. Or you can just loop over the values and add them up – it will be a little less performant, but much easier to grok.

Being able to read mathematical notation is one thing I would say is very useful, and being able to convert that into programming language syntax. Wikipedia is very helpful here, and it means you can find a maths solution then convert it to a programming solution. And picking up the mathematical tricks as and when you need them, building up your knowledge that way, figuring out why they work, that is very useful, but be aware you might not actually use those tricks except in very specific cases.

1 Like

In the real world you probably wont be dealing with math beyond the basics what so ever. Unless you are working on a math related use-case, such as building a game engine, or physics calculations, you probably don’t need much, if any math.

Not to say programming doesn’t require math, its just different. Topics like data structures, algorithms, set theory, and Boolean algebra can all be considered “math”, but still some challenges require knowledge of more advance math topics. The main reason for this is the nature of writing a challenge. Stuff like Codewars wants to test you on “writing code”, but the problems need to be complex enough to challenge you, but short enough to be written in just a few lines. Thus challenges usually require some complex approaches.

I personally hate match, never did well with math, and never want to do anything with tons of math. I do like “Computer Science Math”, like the topics I mentioned above are more my speed. (Boolean Algebra sounds complex, but it isn’t haha) That type of math is better to focus on simply because it’s something you will used day-to-day, its to a point you probably already know most of it haha!

Just keep perspective on what you want to learn. I personally don’t like Codewars too much due to it not being anything like real-world problems most of the time. Its fun every now and then, but so is setting up the architecture of an entire full stack app haha.

Goodluck, don’t get hung up on the maths of things, do it if you want a challenge, or refer to external sources on solving the problems math side. Consider it getting a domain experts help on the topic, but still implement the solution yourself :smiley:


I like to study in Codeforces and CodeChef. You can find all types of problems on both, and you can also find editorials for each problem.

Before competitive programming, I barely know how to think. Take some time to practice, you will see good improvement in short time.

Remember that you should find a study method that fits you.
If you say to me: “Read this book first”, I may be very lazy about that.

Something that works out for me is searching for something I don’t know how to do, then read about it. It motivates me so much, that I learn faster.
It’s all about browse through problems until you struggle at one.
Take care with problems too far away from your current knowledge.

1 Like