Many beginners struggle with programming not because of code, but because of logic. They know the problem… but don’t know what operation to use.
Let’s fix that in a simple way.
🇧🇷 Leia a versão em português no final do post
🧠 What is the problem asking?
Before doing anything, pause for a second and understand the goal of the problem.
Ask yourself: What am I actually trying to find here?
Imagine the problem says: “How long did the car stay in the parking lot?”
At its core, this is just asking for one thing: time
🧠 What information do I already have?
In most of these problems, the situation is very simple.
You usually only know two things:
- when something started
- when it ended
That’s all you get. And from just these two points, you need to figure everything out.
⚙️ Choosing the operation (the important part)
Instead of memorizing rules, think like this:
When things go from one point to another → Subtraction
Imagine you enter a parking lot at 14h and leave at 17h.
How long did you stay?
You are moving from one point in time to another → this is subtraction.
17 - 14 = 3 hours
When you are combining things → Addition
Imagine you study for 2 hours in the morning and 3 hours at night.
How much did you study in total?
You are combining durations → this is addition.
2 + 3 = 5 hours
When something repeats → Multiplication
Imagine you have 4 groups, and each group has 3 items.
How many items in total?
You are repeating the same amount → this is multiplication.
4 × 3 = 12
When you split something → Division
Imagine you have 12 cookies and want to share them equally between 3 people.
How many does each person get?
You are splitting something equally → this is division.
12 ÷ 3 = 4 each
Special case: crossing midnight
Imagine you enter at 22h and leave at 02h.
At first, this looks confusing because the numbers “reset”.
Break it into steps:
22 → 24 = 2 hours
00 → 02 = 2 hours
Total = 4 hours
Another useful trick: minutes
Sometimes working only with hours makes things harder.
So convert everything into minutes.
14:30 → 870 minutes
16:10 → 970 minutes
Now subtract:
970 - 870 = 100 minutes
🧠 Final idea
Programming logic is not about memorizing formulas.
It’s about recognizing patterns:
- Am I moving between points? → subtraction
- Am I combining things? → addition
- Am I repeating? → multiplication
- Am I splitting? → division
🧪 Practice
Try to identify the operation before solving:
10h → 12h
8h → 11h
23h → 03h
14:20 → 15:50
21:45 → 00:15
For each one, ask yourself:
- Am I moving from one point to another?
- Am I combining values?
- Am I repeating something?
- Am I splitting something?
🙏 Thanks for reading
If you read this far, you’re already doing better than most beginners.
Keep practicing — logic becomes natural with time, not memorization.
🇧🇷 Leia a versão em português aqui:
Top comments (0)