Easy problems, step by step
The next step after the basics: you write one function, and the tests call it. Each section practises one idea a few times, so by the end you have seen the tools that most problems are built from.
Challenges
25
Easy
25
Walking through an array
One pass, keeping track of what you have seen so far.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 1.Plus OneAdd one to a number stored as an array of digits. | ArraysMath | Easy | – | ||
| 2.Move ZerosMove every zero to the end, keeping the other numbers in order. | ArraysTwo pointers | Easy | – | ||
| 3.Missing NumberFind the one number missing from 0 to n. | ArraysMathBit manipulation | Easy | – | ||
| 4.Best Time to TradePick one day to buy and a later day to sell for the biggest profit. | ArraysGreedy | Easy | – |
Strings
Compare, scan and convert text.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 5.Valid PalindromeCheck whether text reads the same both ways, ignoring case and punctuation. | StringsTwo pointers | Easy | – | ||
| 6.Longest Common PrefixFind the longest start that every word shares. | Strings | Easy | – | ||
| 7.Roman to IntegerTurn a Roman numeral into a number. | StringsMathHash maps | Easy | – | ||
| 8.First Unique CharacterFind the first letter that appears only once. | StringsHash maps | Easy | – |
Counting with a hash map
Remember counts or positions to answer in one pass.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 9.Contains DuplicateCheck whether any number appears twice. | ArraysHash maps | Easy | – | ||
| 10.Two SumFind the two positions whose numbers add up to a target. | ArraysHash maps | Easy | 100% | ||
| 11.Valid AnagramCheck whether one word is a rearrangement of another. | StringsHash mapsSorting | Easy | – | ||
| 12.Majority ElementFind the value that fills more than half of the array. | ArraysHash maps | Easy | – |
Two pointers, searching and stacks
Move two positions at once, halve the search, and match pairs.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 13.Merge Sorted ArraysMerge two sorted arrays into one sorted array. | ArraysTwo pointersSorting | Easy | – | ||
| 14.Squares of a Sorted ArraySquare every number of a sorted array and keep it sorted. | ArraysTwo pointersSorting | Easy | – | ||
| 15.Binary SearchFind a number's position in a sorted array in log time. | ArraysBinary search | Easy | – | ||
| 16.Valid ParenthesesCheck that every bracket is closed by the right kind, in the right order. | StringsStacks | Easy | – |
Math, bits and a first recursion
Digits, binary, and a problem built from smaller copies of itself.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 17.Palindrome NumberCheck whether a number's digits read the same both ways. | Math | Easy | – | ||
| 18.Count Set BitsCount the 1s in a number's binary form. | Bit manipulationMath | Easy | – | ||
| 19.Single NumberEvery number appears twice except one; find it. | ArraysBit manipulationHash maps | Easy | – | ||
| 20.Climbing StairsCount the ways to climb n stairs taking one or two at a time. | Dynamic programmingMathRecursion | Easy | – |
Linked lists and trees
Nodes that point to other nodes: relink a list, then walk a tree.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 21.Reverse a Linked ListTurn a linked list around so its last node comes first. | Linked lists | Easy | – | ||
| 22.Middle of a Linked ListFind the middle node of a linked list in one pass. | Linked listsTwo pointers | Easy | – | ||
| 23.Merge Two Sorted ListsJoin two sorted linked lists into one sorted list. | Linked listsTwo pointers | Easy | – | ||
| 24.Depth of a TreeCount the levels of a binary tree, from the root to its deepest leaf. | TreesRecursion | Easy | – | ||
| 25.Invert a TreeMirror a binary tree, swapping every node's left and right children. | TreesRecursion | Easy | – |