Roadmap › Stage 1: Foundations (Start Here) › Pattern 1 of 53
DSA pattern guide

Basics — Loops & Math

Warm-up: digits of a number, running totals, simple loops and conditions. Do these if you're new to coding or to your language.

Stage 1 · Foundations (Start Here)8 problems7 Easy · 1 Medium

Use it when

Warm-up: digits of a number, running totals, simple loops and conditions. Do these if you're new to coding or to your language.

Key idea

Break the number or array into steps you can do by hand, then turn each step into a loop. Use n % 10 to get the last digit and n / 10 to drop it.

Practise it right here

4 original problems for this pattern in our free in-browser console. Write Java, Python or JavaScript and get an instant verdict, no install needed.

Open the practice console

Practice problems, in order

  1. Fizz BuzzEasy
  2. Running Sum of 1d ArrayEasy
  3. Richest Customer WealthEasy
  4. Number of Steps to Reduce a Number to ZeroEasy
  5. Count the Digits That Divide a NumberEasy
  6. Palindrome NumberEasy
  7. Plus OneEasy
  8. Reverse IntegerMedium

How to practise this pattern

  1. Read the problem and look for the signal above before writing any code.
  2. Say the brute force out loud, with its time complexity, then ask what work it repeats.
  3. Apply the key idea and write the optimised version yourself.
  4. If you're stuck for more than 10 minutes, take one small hint, not the full solution.
  5. Move to the next problem only when you can explain why this pattern fits.

Stuck on one of these?

The AlgoSolveo extension (free, launching soon) sits beside the LeetCode problem and gives the smallest hint that gets you moving, never the full answer. Solved problems tick off on your roadmap.

Join the extension waitlistTrack it on the roadmap
Next pattern →Arrays — Basics