arrays_strings | ||
images | ||
linked_lists | ||
online_judges | ||
recursion_dynamic | ||
sorting_searching | ||
stacks_queues | ||
templates | ||
__init__.py | ||
.gitignore | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md |
interactive-coding-challenges
Interactive, test-driven coding challenges.
Challenges focus on algorithms and data structures that are typically found in coding interviews or coding competitions.
Each challenge has one or more reference solutions that are:
- Fully functional
- Unit tested
- Easy-to-understand
Notebooks also detail:
- Constraints
- Test cases
- Algorithms
- Big-O time and space complexities
Challenge Solutions
Notebook Structure
Each challenge has two notebooks, a challenge notebook for you to solve and a solution notebook for reference.
Problem Statement
- States the problem to solve.
Constraints
- Describes any constraints or assumptions.
Test Cases
- Describes the general and edge test cases that will be evaluated in the unit test.
Algorithm
- [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.
Code (Challenge: Implement Me!)
- [Challenge Notebook] Skeleton code for you to implement.
- [Solution Notebook] One or more reference solutions.
Unit Test
- [Challenge Notebook] Unit test for your code. Expected to fail until you solve the challenge.
- [Solution Notebook] Unit test for the reference solution(s).
Future Development
Challenges, solutions, and unit tests are presented in the form of IPython/Jupyter Notebooks.
- Notebooks currently contain mostly Python solutions, but can be extended to include 44 supported languages
- Repo will be continually updated with new solutions and challenges
Contributing
Contributions are welcome!
Review the Contributing Guidelines for details on how to:
- Submit issues
- Add solutions to existing challenges
- Add new challenges
Index
Challenges Categories
- Arrays and Strings
- Linked Lists
- Stacks and Queues
- Sorting and Searching
- Recursion and Dynamic Programming
- Trees and Graphs
- Bit Manipulation
- Scalability and Memory Limits
- Concurrency
- Online Judges
Installing and Running Challenges
Misc
Challenges
Arrays and Strings
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 |
Implement a hash table | 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 |
Linked Lists
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 |
Stacks and Queues
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 the Towers of Hanoi with 3 towers and N disks | 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 |
Add a challenge | Contribute│Contribute |
Sorting and Searching
Challenge | Static Notebooks |
---|---|
Implement selection sort | Challenge│Solution |
Implement insertion sort | Challenge│Solution |
Implement quick sort | Challenge│Solution |
Implement merge sort | 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 |
Sort an array of strings so all anagrams are next to each other | Contribute│Contribute |
Find an element in a rotated and sorted array of integers | Contribute│Contribute |
Add a challenge | Contribute│Contribute |
Recursion and Dynamic Programming
Challenge | Static Notebooks |
---|---|
Implement fibonacci recursively, dynamically, and iteratively | Challenge│Solution |
Implement factorial recursively, dynamically, and iteratively | Contribute│Contribute |
Perform a binary search on a sorted array of integers | Contribute│Contribute |
Print all subsets of a set | Contribute│Contribute |
Print all permutations of a string | Contribute│Contribute |
Print all combinations of a string | Contribute│Contribute |
Print all valid combinations of n-pairs of parentheses | 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 |
Trees and Graphs
Challenge | Static Notebooks |
---|---|
Implement breadth-first search | Contribute│Contribute |
Implement depth-first search | Contribute│Contribute |
Print a tree using pre-order traversal | Contribute│Contribute |
Print a tree using pre-order traversal without recursion | Contribute│Contribute |
Print a tree using in-order traversal | Contribute│Contribute |
Print a tree using post-order traversal | Contribute│Contribute |
Determine the height of a tree | Contribute│Contribute |
Determine the lowest common ancestor of two nodes | Contribute│Contribute |
Transform a binary tree into a heap | Contribute│Contribute |
Implement a right and left rotation on a tree | Contribute│Contribute |
Check if a binary tree is balanced | Contribute│Contribute |
Check if a binary tree is binary search tree | Contribute│Contribute |
Add a challenge | Contribute│Contribute |
Mathematics and Probability
Challenge | Static Notebooks |
---|---|
Check if a number is prime | Contribute│Contribute |
Generate a list of primes | 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 |
Bit Manipulation
Challenge | Static Notebooks |
---|---|
Given a number between 0 and 1, print the binary representation | Contribute│Contribute |
Determine the number of bits required to convert integer A to integer B | Contribute│Contribute |
Swap odd and even bits in an integer with as few instructions as possible | Contribute│Contribute |
Determine the number of 1 bits in the binary representation of a given integer | Contribute│Contribute |
Add a challenge | Contribute│Contribute |
Online Judges
Challenge | Static Notebooks |
---|---|
Utopian tree | Challenge│Solution |
Maximizing xor | Challenge│Solution |
Add a challenge | Contribute│Contribute |
Notebook Installation
If you already have Python installed and are familiar with installing packages, you can get IPython with pip:
pip install ipython
Or if you want to also get the dependencies for the IPython notebook:
pip install "ipython[notebook]"
For more details on installation, follow the directions here.
To interact with or to modify elements within the IPython notebooks, you must first clone or download the repository then run the ipython notebook. More information on IPython Notebooks can be found here.
$ git clone https://github.com/donnemartin/interactive-coding-challenges.git
$ cd [downloaded repo directory name]
$ ipython notebook
Notebook tested with Python 2.7.x.
Credits
- Cracking the Coding Interview | GitHub
- Elements of Programming Interviews | GitHub
- Programming Interviews Exposed
- The Algorithm Design Manual | Selected Solutions
- CareerCup
- Quora
- HackerRank
- TopCoder
Contributing
Contributions are welcome!
For bug reports or requests please submit an issue.
For pull requests, please follow the general notebook format.
Contact Info
Feel free to contact me to discuss any issues, questions, or comments.
- Email: donne.martin@gmail.com
- Twitter: @donne_martin
- GitHub: donnemartin
- LinkedIn: donnemartin
- Website: donnemartin.com
License
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.