Never coded?
Coding basics
Watch one crash course, then write your first programs. Each problem starts with the one new idea it needs and a tiny example. When these feel easy, move on to the warm-ups.
Step 0 · Learn the fundamentals
New to coding too? Start with Step 0
DSA problems assume you can write basic code. Pick one language, watch its crash course, then write your first programs in the coding basics. Already comfortable in one? Go to the warm-ups.
The editor here runs Python. Learning Java or C++? Write your answer in your language first (on paper or in your own editor), then check the solution in that language.
0/20 coding basics done
Start: Even or odd →Decisions
if, elif and else: do different things for different inputs.
- Even or oddReturn True if the number n is even, False if it's odd.
- Biggest of three numbersReturn the largest of the three numbers a, b and c, without using max().
- Score to letter gradeTurn a score from 0 to 100 into a grade: 90 and above is "A", 80–89 "B", 70–79 "C", 60–69 "D", below 60 "F".
- Leap yearA year is a leap year if it's divisible by 4, except years divisible by 100, which are leap years only if also divisible by 400. Return True or False.
Loops
Repeat a step: for, range and while.
- Add up 1 to nReturn 1 + 2 + … + n. For n = 0 the sum is 0.
- Multiplication tableReturn the first ten multiples of n as a list: [n×1, n×2, …, n×10].
- FizzBuzzFor each number from 1 to n, add "Fizz" if it's divisible by 3, "Buzz" if by 5, "FizzBuzz" if by both, and otherwise the number itself as text. Return the list.
- FactorialReturn n! = 1 × 2 × … × n. By definition 0! is 1.
- Power without **Return base raised to exp (exp is 0 or more), using a loop instead of ** or pow().
- Star triangleReturn n rows of a triangle as a list of strings: row 1 is "*", row 2 is "**", up to n stars.
Numbers and digits
% and // to take numbers apart.
- Count the digitsReturn how many digits a non-negative integer n has.
- Sum of digitsReturn the sum of the digits of a non-negative integer n.
- Reverse a numberReturn the digits of a non-negative integer n in reverse order, as a number (so 1200 becomes 21).
- Is it prime?Return True if n is prime: bigger than 1 and divisible only by 1 and itself.
- Greatest common divisorReturn the largest number that divides both a and b (both non-negative, not both 0).
- First n Fibonacci numbersReturn the first n Fibonacci numbers: 0, 1, then each number is the sum of the two before it.
Lists and text
Walk a list or a string and build an answer.
- Sum of a listReturn the sum of the numbers in the list, without using sum(). An empty list sums to 0.
- Count the even numbersReturn how many numbers in the list are even.
- Square every numberReturn a new list with each number squared, in the same order.
- Count the vowelsReturn how many vowels (a, e, i, o, u, upper or lower case) are in the string.