Beginner Problems: Strings, Arrays and Numbers
Friendly warm-ups for your first weeks of coding: strings, arrays and numbers, each with hints, an explanation and tests that run in your browser.
- Reverse a String Return the characters of a string in reverse order.
- Count the Vowels Count how many vowels (a, e, i, o, u) a string contains, ignoring case.
- Capitalize Each Word Make the first letter of every word upper case.
- Longest Word in a Sentence Find the longest word in a sentence; if there's a tie, return the first one.
- Run-Length Encoding Compress a string by replacing each run of the same character with the character and the run's length.
- Is It a Pangram? Check whether a sentence uses every letter of the alphabet at least once.
- Make an Acronym Build an acronym from the first letter of each word, in upper case.
- Caesar Cipher Shift every letter forward in the alphabet by a fixed amount, wrapping from z back to a.
- Reverse the Words Reverse the order of the words in a sentence.
- First Unique Character Return the index of the first character that appears only once, or -1.
- Roman Numerals to Integer Convert a Roman numeral such as MCMXCIV into an integer.
- Longest Common Prefix Find the longest starting text that every word in a list shares.
- Valid Username Check a username against simple rules: length, allowed characters and a starting letter.
- Sum of an Array Add up all the numbers in an array.
- Find the Maximum Find the largest number in a non-empty array without using a built-in max.
- Count the Even Numbers Count how many numbers in an array are even.
- Second Largest Number Find the second-largest distinct value in an array, or -1 if there isn't one.
- Running Sum Return the running totals of an array: each position holds the sum of everything up to it.
- Remove Duplicates (Keep Order) Remove repeated values from an array, keeping the first occurrence of each in the original order.
- Rotate an Array Rotate an array to the right by k steps.
- Merge Two Sorted Arrays Combine two sorted arrays into one sorted array.
- Move Zeroes to the End Move all zeros to the end of an array while keeping the order of the other numbers.
- Find the Missing Number An array holds every number from 0 to n except one; find the missing one.
- Longest Run of Ones Find the length of the longest run of consecutive 1s in an array of 0s and 1s.
- Intersection of Two Arrays Return the distinct values that appear in both arrays, sorted ascending.
- Majority Element Find the value that appears more than half the time.
- Squares of a Sorted Array Square every number of a sorted array (which may contain negatives) and return the squares sorted.
- Plus One Add one to a number stored as an array of digits.
- The Single Number Every number appears twice except one; find it.
- Pascal's Triangle Row Return one row of Pascal's triangle, where each number is the sum of the two above it.
- FizzBuzz The classic: count from 1 to n, replacing multiples of 3 with Fizz, of 5 with Buzz, and of both with FizzBuzz.
- Factorial Compute n! = 1 × 2 × ... × n.
- Fibonacci Number Return the nth Fibonacci number, where each number is the sum of the two before it.
- Is It Prime? Check whether a number is prime by testing divisors up to its square root.
- Greatest Common Divisor Find the largest number that divides two numbers, with Euclid's algorithm.
- Sum of Digits Add up the digits of a non-negative integer.
- Power of Two Check whether a number is a power of two (1, 2, 4, 8, ...).
- Count Primes Below n Count the prime numbers less than n using the Sieve of Eratosthenes.
- Leap Year Decide whether a year is a leap year in the Gregorian calendar.
- Reverse an Integer Reverse the digits of an integer, keeping its sign.
- Armstrong Number Check whether a number equals the sum of its digits each raised to the number of digits.