FMTechnical notesPortfolio
Back to the blog

Fundamentos · Beginner

Logic and algorithms without the mystery

An algorithm is a finite, verifiable recipe. The hard part is not writing the loop; it is defining exactly what must happen in every case.

After reading this
  • Turn ambiguous requirements into cases
  • Write pseudocode
  • Compare solutions by cost
01 / 03

Break the problem down

Define normal examples, boundaries, and errors. If you cannot predict the output for a small input, the rule is not clear yet.

  • What do I receive?
  • Which constraints exist?
  • What must I return?
  • What happens with zero, empty, or repeated values?
02 / 03

Pseudocode first

Pseudocode keeps syntax out of the conversation while you are still designing the solution.

text
FOR each order
  IF order is paid
    add order.total
RETURN sum
03 / 03

Cost is part of the solution

Traversing a collection once is usually O(n). Two nested traversals often approach O(n²). Big O describes growth, not today's milliseconds.

js
const paidTotal = orders
  .filter((order) => order.paid)
  .reduce((total, order) => total + order.total, 0);
Complexity view● interactive
INPUTRULECHECKOUTPUT
Practice

Think before coding

Given a list of emails, return the duplicates without repeating them in the result.

Show a hint

A Set can remember which values have already appeared.