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.
0/24 warm-ups done
Start: Largest and smallest element →Arrays
Loops, indexes, edge cases and changing an array in place.
- Largest and smallest elementGiven a non-empty array of integers, return [smallest, largest].
- 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).
- Check if an array is sortedReturn true if the array is in non-decreasing order (each element ≤ the next), otherwise false.
- Reverse an array in placeReverse the array without creating a new one. Change nums itself; return nothing.
- 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.
- 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.
- 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.
- Find the missing number from 1 to nnums holds every number from 1 to n except one, in any order. Return the missing number.
- Linear searchReturn the index of the first element equal to target, or -1 if it isn't in the array.
- Running sum (prefix sums)Return an array where each position holds the sum of all numbers up to and including that position.
- Count how often each number appearsReturn a list of [value, count] pairs, one per distinct value, sorted by value.
- Merge two sorted arraysGiven two sorted arrays, return one sorted array with all their elements.
Strings
Characters, counting, and building a new string.
- Reverse a string (no built-in reverse)Return the string reversed, without using a built-in reverse (no [::-1], reversed() or .reverse()).
- Check if a string is a palindromeReturn true if the string reads the same forwards and backwards (compare characters exactly, case matters).
- 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.
- Frequency of each characterReturn "char:count" for every distinct character, in the order each character first appears.
- Remove duplicate characters, keep the firstReturn the string with repeated characters removed, keeping each character's first occurrence in order.
- Reverse the order of wordsReturn the words in reverse order, separated by single spaces, with no spaces at the start or end.
- First non-repeating characterReturn the index of the first character that appears exactly once, or -1 if there's none.
- 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.
- Check if two strings are rotationsReturn true if goal can be made by moving some characters from the front of s to its end.
- 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.
- 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.
- 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.