Arrays for Beginners
Sums, maximums, duplicates, rotations and merges: get comfortable looping over arrays before the classic patterns.
- 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.