Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

Know a language?

Warm-ups

Before LeetCode-style problems, make sure these feel easy: walking an array, swapping, counting and building strings. Know some already? Take the quick check to skip ahead. Never coded? Start with coding basics.

Arrays

Loops, indexes, edge cases and changing an array in place.

  1. Largest and smallest elementGiven a non-empty array of integers, return [smallest, largest].
  2. Second-largest distinct elementReturn the second-largest distinct value in the array, or -1 if there isn't one (all values equal, or only one element).
  3. Check if an array is sortedReturn true if the array is in non-decreasing order (each element ≤ the next), otherwise false.
  4. Reverse an array in placeReverse the array without creating a new one. Change nums itself; return nothing.
  5. Left-rotate an array by kReturn the array rotated left by k positions: the first k elements move to the end, in order. k can be larger than the length.
  6. Move zeros to the endMove every 0 to the end of the array while keeping the other numbers in their original order. Change nums in place.
  7. Remove duplicates from a sorted arrayThe array is sorted. Remove the duplicates in place so each value appears once at the front, and return how many unique values there are.
  8. Find the missing number from 1 to nnums holds every number from 1 to n except one, in any order. Return the missing number.
  9. Linear searchReturn the index of the first element equal to target, or -1 if it isn't in the array.
  10. Running sum (prefix sums)Return an array where each position holds the sum of all numbers up to and including that position.
  11. Count how often each number appearsReturn a list of [value, count] pairs, one per distinct value, sorted by value.
  12. Merge two sorted arraysGiven two sorted arrays, return one sorted array with all their elements.

Strings

Characters, counting, and building a new string.

  1. Reverse a string (no built-in reverse)Return the string reversed, without using a built-in reverse (no [::-1], reversed() or .reverse()).
  2. Check if a string is a palindromeReturn true if the string reads the same forwards and backwards (compare characters exactly, case matters).
  3. Count vowels, consonants, digits and special charactersReturn [vowels, consonants, digits, special]. Letters count in either case; special means anything that isn't a letter, digit or space.
  4. Frequency of each characterReturn "char:count" for every distinct character, in the order each character first appears.
  5. Remove duplicate characters, keep the firstReturn the string with repeated characters removed, keeping each character's first occurrence in order.
  6. Reverse the order of wordsReturn the words in reverse order, separated by single spaces, with no spaces at the start or end.
  7. First non-repeating characterReturn the index of the first character that appears exactly once, or -1 if there's none.
  8. Check if two strings are anagramsReturn true if t uses exactly the same characters as s, the same number of times each, in any order.
  9. Check if two strings are rotationsReturn true if goal can be made by moving some characters from the front of s to its end.
  10. Count the words in a sentenceReturn how many words the string has. Words are separated by one or more spaces, and there may be spaces at either end.
  11. Capitalize the first letter of each wordReturn the string with the first letter of every word in uppercase and all other letters in lowercase. Words are separated by single spaces.
  12. Most frequent characterReturn the character that appears most often. If several tie, return the one that appears first in the string. Return "" for an empty string.