Arrays for Beginners

Sums, maximums, duplicates, rotations and merges: get comfortable looping over arrays before the classic patterns.

  1. Sum of an Array Add up all the numbers in an array. Easy All 5 languages
  2. Find the Maximum Find the largest number in a non-empty array without using a built-in max. Easy All 5 languages
  3. Count the Even Numbers Count how many numbers in an array are even. Easy All 5 languages
  4. Second Largest Number Find the second-largest distinct value in an array, or -1 if there isn't one. Easy All 5 languages
  5. Running Sum Return the running totals of an array: each position holds the sum of everything up to it. Easy All 5 languages
  6. Remove Duplicates (Keep Order) Remove repeated values from an array, keeping the first occurrence of each in the original order. Easy All 5 languages
  7. Rotate an Array Rotate an array to the right by k steps. Easy All 5 languages
  8. Merge Two Sorted Arrays Combine two sorted arrays into one sorted array. Easy All 5 languages
  9. 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
  10. Find the Missing Number An array holds every number from 0 to n except one; find the missing one. Easy All 5 languages
  11. 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
  12. Intersection of Two Arrays Return the distinct values that appear in both arrays, sorted ascending. Easy All 5 languages
  13. Majority Element Find the value that appears more than half the time. Easy All 5 languages
  14. 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
  15. Plus One Add one to a number stored as an array of digits. Easy All 5 languages
  16. The Single Number Every number appears twice except one; find it. Easy All 5 languages
  17. 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

← All coding problems

Was this page helpful?