120+ continually updated, interactive, and test-driven coding challenges, with Anki flashcards.
Challenges focus on algorithms and data structures found in coding interviews.
Each challenge has one or more reference solutions that are:
- Fully functional
- Unit tested
- Easy-to-understand
Challenges will soon provide on-demand incremental hints to help you arrive at the optimal solution.
Notebooks also detail:
- Constraints
- Test cases
- Algorithms
- Big-O time and space complexities
Also included are unit tested reference implementations of various data structures and algorithms.
The provided Anki flashcard deck uses spaced repetition to help you retain key concepts.
Great for use while on-the-go.
Looking for resources to help you prep for the System Design and Object-Oriented Design interviews?
Check out the sister repo The System Design Primer, which contains additional Anki decks:
Each challenge has two notebooks, a challenge notebook with unit tests for you to solve and a solution notebook for reference.
- States the problem to solve.
- Describes any constraints or assumptions.
- Describes the general and edge test cases that will be evaluated in the unit test.
- [Challenge Notebook] Empty, refer to the solution notebook algorithm section if you need a hint.
- [Solution Notebook] One or more algorithm solution discussions, with Big-O time and space complexities.
- [Challenge Notebook] Provides on-demand incremental hints to help you arrive at the optimal solution. Coming soon!
- [Challenge Notebook] Skeleton code for you to implement.
- [Solution Notebook] One or more reference solutions.
- [Challenge Notebook] Unit test for your code. Expected to fail until you solve the challenge.
- [Solution Notebook] Unit test for the reference solution(s).
Format: Challenge Category - Number of Challenges
- Arrays and Strings - 10
- Linked Lists - 8
- Stacks and Queues - 8
- Graphs and Trees - 21
- Sorting - 10
- Recursion and Dynamic Programming - 17
- Mathematics and Probability - 6
- Bit Manipulation - 8
- Online Judges - 16
- System Design - 8
- Object Oriented Design - 8
Total number of challenges: 120
Unit tested, fully functional implementations of the following data structures:
Unit tested, fully functional implementations of the following algorithms:
- Selection Sort
- Insertion Sort
- Quick Sort
- Merge Sort
- Radix Sort
- Topological Sort
- Tree Depth-First Search (Pre-, In-, Post-Order)
- Tree Breadth-First Search
- Graph Depth-First Search
- Graph Breadth-First Search
- Dijkstra's Shortest Path
- Unweighted Graph Shortest Path
- Knapsack 0/1
- Knapsack Unbounded
- Sieve of Eratosthenes
- A*
- Bellman-Ford
- Bloom Filter
- Convex Hull
- Fisher-Yates Shuffle
- Kruskal's
- Max Flow
- Prim's
- Rabin-Karp
- Traveling Salesman
- Union Find
- Contribute
Challenge | Static Notebook |
---|---|
Determine if a string contains unique characters | ChallengeβSolution |
Determine if a string is a permutation of another | ChallengeβSolution |
Determine if a string is a rotation of another | ChallengeβSolution |
Compress a string | ChallengeβSolution |
Reverse characters in a string | ChallengeβSolution |
Given two strings, find the single different char | ChallengeβSolution |
Find two indices that sum to a specific value | ChallengeβSolution |
Implement a hash table | ChallengeβSolution |
Implement fizz buzz | ChallengeβSolution |
Find the first non-repeated character in a string | ContributeβContribute |
Remove specified characters in a string | ContributeβContribute |
Reverse words in a string | ContributeβContribute |
Convert a string to an integer | ContributeβContribute |
Convert an integer to a string | ContributeβContribute |
Add a challenge | ContributeβContribute |
Challenge | Static Notebook |
---|---|
Remove duplicates from a linked list | ChallengeβSolution |
Find the kth to last element of a linked list | ChallengeβSolution |
Delete a node in the middle of a linked list | ChallengeβSolution |
Partition a linked list around a given value | ChallengeβSolution |
Add two numbers whose digits are stored in a linked list | ChallengeβSolution |
Find the start of a linked list loop | ChallengeβSolution |
Determine if a linked list is a palindrome | ChallengeβSolution |
Implement a linked list | ChallengeβSolution |
Determine if a list is cyclic or acyclic | ContributeβContribute |
Add a challenge | ContributeβContribute |
Challenge | Static Notebook |
---|---|
Implement n stacks using a single array | ChallengeβSolution |
Implement a stack that keeps track of its minimum element | ChallengeβSolution |
Implement a set of stacks class that wraps a list of capacity-bounded stacks | ChallengeβSolution |
Implement a queue using two stacks | ChallengeβSolution |
Sort a stack using another stack as a buffer | ChallengeβSolution |
Implement a stack | ChallengeβSolution |
Implement a queue | ChallengeβSolution |
Implement a priority queue backed by an array | ChallengeβSolution |
Add a challenge | ContributeβContribute |
Challenge | Static Notebooks |
---|---|
Implement depth-first search (pre-, in-, post-order) on a tree | ChallengeβSolution |
Implement breadth-first search on a tree | ChallengeβSolution |
Determine the height of a tree | ChallengeβSolution |
Create a binary search tree with minimal height from a sorted array | ChallengeβSolution |
Create a linked list for each level of a binary tree | ChallengeβSolution |
Check if a binary tree is balanced | ChallengeβSolution |
Determine if a tree is a valid binary search tree | ChallengeβSolution |
Find the in-order successor of a given node in a binary search tree | ChallengeβSolution |
Find the second largest node in a binary search tree | ChallengeβSolution |
Find the lowest common ancestor | ChallengeβSolution |
Invert a binary tree | ChallengeβSolution |
Implement a binary search tree | ChallengeβSolution |
Implement a min heap | ChallengeβSolution |
Implement a trie | ChallengeβSolution |
Implement depth-first search on a graph | ChallengeβSolution |
Implement breadth-first search on a graph | ChallengeβSolution |
Determine if there is a path between two nodes in a graph | ChallengeβSolution |
Implement a graph | ChallengeβSolution |
Find a build order given a list of projects and dependencies. | ChallengeβSolution |
Find the shortest path in a weighted graph. | ChallengeβSolution |
Find the shortest path in an unweighted graph. | ChallengeβSolution |
Add a challenge | ContributeβContribute |
Challenge | Static Notebooks |
---|---|
Implement selection sort | ChallengeβSolution |
Implement insertion sort | ChallengeβSolution |
Implement quick sort | ChallengeβSolution |
Implement merge sort | ChallengeβSolution |
Implement radix sort | ChallengeβSolution |
Sort an array of strings so all anagrams are next to each other | ChallengeβSolution |
Find an item in a sorted, rotated array | ChallengeβSolution |
Search a sorted matrix for an item | ChallengeβSolution |
Find an int not in an input of n integers | ChallengeβSolution |
Given sorted arrays A, B, merge B into A in sorted order | ChallengeβSolution |
Implement a stable selection sort | ContributeβContribute |
Make an unstable sort stable | ContributeβContribute |
Implement an efficient, in-place version of quicksort | ContributeβContribute |
Given two sorted arrays, merge one into the other in sorted order | ContributeβContribute |
Find an element in a rotated and sorted array of integers | ContributeβContribute |
Add a challenge | ContributeβContribute |
Challenge | Static Notebooks |
---|---|
Implement fibonacci recursively, dynamically, and iteratively | ChallengeβSolution |
Maximize items placed in a knapsack | ChallengeβSolution |
Maximize unbounded items placed in a knapsack | ChallengeβSolution |
Find the longest common subsequence | ChallengeβSolution |
Find the longest increasing subsequence | ChallengeβSolution |
Minimize the cost of matrix multiplication | ChallengeβSolution |
Maximize stock prices given k transactions | ChallengeβSolution |
Find the minimum number of ways to represent n cents given an array of coins | ChallengeβSolution |
Find the unique number of ways to represent n cents given an array of coins | ChallengeβSolution |
Print all valid combinations of n-pairs of parentheses | ChallengeβSolution |
Navigate a maze | ChallengeβSolution |
Print all subsets of a set | ChallengeβSolution |
Print all permutations of a string | ChallengeβSolution |
Find the magic index in an array | ChallengeβSolution |
Find the number of ways to run up n steps | ChallengeβSolution |
Implement the Towers of Hanoi with 3 towers and N disks | ChallengeβSolution |
Implement factorial recursively, dynamically, and iteratively | ContributeβContribute |
Perform a binary search on a sorted array of integers | ContributeβContribute |
Print all combinations of a string | ContributeβContribute |
Implement a paint fill function | ContributeβContribute |
Find all permutations to represent n cents, given 1, 5, 10, 25 cent coins | ContributeβContribute |
Add a challenge | ContributeβContribute |
Challenge | Static Notebooks |
---|---|
Generate a list of primes | ChallengeβSolution |
Find the digital root | ChallengeβSolution |
Create a class supporting insert, max, min, mean, mode in O(1) | ChallengeβSolution |
Determine if a number is a power of two | ChallengeβSolution |
Add two numbers without the + or - sign | ChallengeβSolution |
Subtract two numbers without the + or - sign | ChallengeβSolution |
Check if a number is prime | ContributeβContribute |
Determine if two lines on a Cartesian plane intersect | ContributeβContribute |
Using only add, implement multiply, subtract, and divide for ints | ContributeβContribute |
Find the kth number such that the only prime factors are 3, 5, and 7 | ContributeβContribute |
Add a challenge | ContributeβContribute |
Challenge | Static Notebooks |
---|---|
Implement common bit manipulation operations | ChallengeβSolution |
Determine number of bits to flip to convert a into b | ChallengeβSolution |
Draw a line on a screen | ChallengeβSolution |
Flip a bit to maximize the longest sequence of 1s | ChallengeβSolution |
Get the next largest and next smallest numbers | ChallengeβSolution |
Merge two binary numbers | ChallengeβSolution |
Swap odd and even bits in an integer | ChallengeβSolution |
Print the binary representation of a number between 0 and 1 | ChallengeβSolution |
Determine the number of 1s in the binary representation of a given integer | ContributeβContribute |
Add a challenge | ContributeβContribute |
Challenge | Static Notebooks |
---|---|
Find the longest substring with at most k distinct chars | ChallengeβSolution |
Find the highest product of three numbers | ChallengeβSolution |
Maximize stocks profit from 1 buy and 1 sell | ChallengeβSolution |
Move all zeroes in a list to the end | ChallengeβSolution |
Find the products of every other int | ChallengeβSolution |
Given a list of entries and exits, find the busiest period | ChallengeβSolution |
Determine an island's perimeter | ChallengeβSolution |
Format license keys | ChallengeβSolution |
Find the longest absolute file path | ChallengeβSolution |
Merge tuple ranges | ChallengeβSolution |
Assign cookies | ChallengeβSolution |
Determine if you can win in Nim | ChallengeβSolution |
Check if a magazine could have been used to create a ransom note | ChallengeβSolution |
Find the number of times a sentence can fit on a screen | ChallengeβSolution |
Utopian tree | ChallengeβSolution |
Maximizing xor | ChallengeβSolution |
Add a challenge | ContributeβContribute |
interactive-coding-challenges # Repo
ββ arrays_strings # Category of challenges
β ββ rotation # Challenge folder
β β ββ rotation_challenge.ipynb # Challenge notebook
β β ββ rotation_solution.ipynb # Solution notebook
β β ββ test_rotation.py # Unit test*
β ββ compress
β β ββ compress_challenge.ipynb
β β ββ compress_solution.ipynb
β β ββ test_compress.py
β ββ ...
ββ linked_lists
β ββ palindrome
β β ββ ...
β ββ ...
ββ ...
*The notebooks (.ipynb) read/write the associated unit test (.py) file.
Run:
pip install jupyter
For detailed instructions, scripts, and tools to more optimally set up your development environment, check out the dev-setup repo.
For more details on notebook installation, follow the directions here.
More information on IPython/Jupyter Notebooks can be found here.
Install nose using setuptools/distribute:
easy_install nose
or
pip install nose
More information on Nose can be found here.
Challenges are provided in the form of IPython/Jupyter Notebooks and have been tested with Python 2.7 and Python 3.x.
If you need to install IPython/Jupyter Notebook, see the Notebook Installation section.
- This README contains links to nbviewer, which hosts static notebooks of the repo's contents
- To interact with or to modify elements within the dynamic notebooks, refer to the instructions below
Run the notebook of challenges:
$ git clone https://github.com/donnemartin/interactive-coding-challenges.git
$ cd interactive-coding-challenges
$ jupyter notebook
This will launch your web browser with the list of challenge categories:
- Navigate to the Challenge Notebook you wish to solve
- Run the cells within the challenge notebook (Cell->Run All)
- This will result in an expected unit test error
- Solve the challenge and verify it passes the unit test
- Check out the accompanying Solution Notebook for further discussion
To debug your solution with pdb, refer to the following ticket.
Note: If your solution is different from those listed in the Solution Notebook, consider submitting a pull request so others can benefit from your work. Review the Contributing Guidelines for details.
Challenges, solutions, and unit tests are presented in the form of IPython/Jupyter Notebooks.
- Notebooks currently contain mostly Python solutions (tested on both Python 2.7 and Python 3.x), but can be extended to include 40+ supported languages
- Repo will be continually updated with new solutions and challenges
- Contributions are welcome!
Contributions are welcome!
Review the Contributing Guidelines for details on how to:
- Submit issues
- Add solutions to existing challenges
- Add new challenges
- Cracking the Coding Interview | GitHub Solutions
- Programming Interviews Exposed
- The Algorithm Design Manual | Solutions
- CareerCup
- Quora
- HackerRank
- LeetCode
- Arrays and Strings: nltk.org
- Linked Lists: wikipedia.org
- Stacks: wikipedia.org
- Queues: wikipedia.org
- Sorting: wikipedia.org
- Recursion and Dynamic Programming: wikipedia.org
- Graphs and Trees: wikipedia.org
- Mathematics and Probability: wikipedia.org
- Bit Manipulation: wikipedia.org
- Online Judges: topcoder.com
Feel free to contact me to discuss any issues, questions, or comments.
My contact info can be found on my GitHub page.
I am providing code and resources in this repository to you under an open source license. Because this is my personal repository, the license you receive to my code and resources is from me and not my employer (Facebook).
Copyright 2015 Donne Martin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.