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.

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

← All coding problems

Was this page helpful?