interactive-coding-challenges
120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
Top Related Projects
Interactive roadmaps, guides and other educational content to help developers grow in their careers.
A complete computer science study plan to become a software engineer.
💯 Curated coding interview preparation materials for busy software engineers
All Algorithms implemented in Python
:books: Freely available programming books
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
Quick Overview
The "interactive-coding-challenges" repository by donnemartin is a comprehensive collection of Python coding challenges with Jupyter notebook solutions. It covers various computer science topics, including data structures, algorithms, and system design, providing an interactive learning experience for software engineers preparing for technical interviews or improving their coding skills.
Pros
- Extensive coverage of important CS topics and interview questions
- Interactive Jupyter notebook format for easy practice and learning
- Well-organized structure with clear explanations and multiple solutions
- Regularly updated with new challenges and improvements
Cons
- Primarily focused on Python, limiting its usefulness for other languages
- Some challenges may be too advanced for beginners
- Solutions are readily available, which might tempt users to look at answers too quickly
- Lacks a built-in testing or grading system for self-assessment
Code Examples
This repository is not a code library but a collection of coding challenges. Therefore, there are no specific code examples to showcase. Instead, users interact with Jupyter notebooks containing the challenges and their solutions.
Getting Started
To get started with the interactive-coding-challenges:
-
Clone the repository:
git clone https://github.com/donnemartin/interactive-coding-challenges.git
-
Install the required dependencies:
pip install -r requirements.txt
-
Launch Jupyter Notebook:
jupyter notebook
-
Navigate to the desired challenge category and open the corresponding notebook to begin practicing.
Competitor Comparisons
Interactive roadmaps, guides and other educational content to help developers grow in their careers.
Pros of developer-roadmap
- Provides comprehensive visual roadmaps for various tech career paths
- Regularly updated with current industry trends and technologies
- Offers a clear, structured learning path for beginners and experienced developers
Cons of developer-roadmap
- Lacks hands-on coding challenges or exercises
- May be overwhelming for absolute beginners due to the breadth of information
- Doesn't provide in-depth explanations or resources for each topic
Code comparison
Not applicable, as developer-roadmap doesn't contain code samples, while interactive-coding-challenges focuses on providing coding exercises.
Additional notes
interactive-coding-challenges offers:
- Hands-on coding exercises with solutions
- Unit tests for verifying solutions
- In-depth explanations of algorithms and data structures
developer-roadmap provides:
- Visual guides for different tech career paths
- High-level overview of technologies and concepts
- Community-driven content updates
Both repositories serve different purposes:
- interactive-coding-challenges is ideal for practicing coding skills and preparing for technical interviews
- developer-roadmap is better suited for planning long-term learning goals and understanding the broader tech landscape
Choose based on your current learning needs: hands-on practice or career guidance.
A complete computer science study plan to become a software engineer.
Pros of Coding Interview University
- Comprehensive curriculum covering a wide range of computer science topics
- Well-structured learning path with clear progression
- Includes additional resources like books, videos, and practice problems
Cons of Coding Interview University
- Less hands-on coding practice compared to Interactive Coding Challenges
- May be overwhelming for beginners due to the extensive content
- Lacks interactive elements for immediate feedback
Code Comparison
While both repositories focus on interview preparation, they don't provide direct code comparisons. Interactive Coding Challenges offers more coding exercises, while Coding Interview University focuses on theoretical concepts and resources.
Interactive Coding Challenges example:
class Solution(object):
def two_sum(self, nums, target):
# Implementation here
pass
Coding Interview University doesn't typically include code snippets, but rather links to external resources and explanations of concepts.
Summary
Interactive Coding Challenges is more focused on hands-on coding practice with specific problem sets, while Coding Interview University provides a comprehensive curriculum covering various computer science topics. The choice between the two depends on the learner's preference for practical coding exercises versus a broader theoretical foundation.
💯 Curated coding interview preparation materials for busy software engineers
Pros of tech-interview-handbook
- Comprehensive coverage of non-technical aspects of interviews (e.g., behavioral questions, resume tips)
- Regularly updated with current industry trends and practices
- Well-organized structure with clear navigation and categorization
Cons of tech-interview-handbook
- Less focus on hands-on coding challenges and problem-solving
- May lack depth in certain algorithmic topics compared to interactive-coding-challenges
- Limited interactive elements for practicing coding skills
Code Comparison
tech-interview-handbook:
// Example of a coding question from the handbook
function twoSum(nums, target) {
const map = new Map();
for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if (map.has(complement)) {
return [map.get(complement), i];
}
map.set(nums[i], i);
}
}
interactive-coding-challenges:
# Example of an interactive coding challenge
class Solution(object):
def two_sum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
# Implement your solution here
The tech-interview-handbook provides a complete solution, while interactive-coding-challenges encourages users to implement the solution themselves, promoting active learning and problem-solving skills.
All Algorithms implemented in Python
Pros of Python
- Extensive collection of algorithms covering various categories
- Well-organized directory structure for easy navigation
- Active community with frequent contributions and updates
Cons of Python
- Lacks interactive coding challenges and problem-solving exercises
- Minimal explanations or documentation for each algorithm
- No built-in testing framework or unit tests for verifying implementations
Code Comparison
interactive-coding-challenges:
class Solution(object):
def reverse(self, data):
if data is None:
return None
return data[::-1]
Python:
def reverse_string(string: str) -> str:
return string[::-1]
Both repositories implement string reversal, but interactive-coding-challenges includes error handling and is part of a class-based solution, while Python offers a simpler, standalone function.
Summary
interactive-coding-challenges focuses on interactive problem-solving with explanations and tests, while Python provides a comprehensive collection of algorithm implementations. The former is better for learning and practice, while the latter serves as a reference for various algorithms in Python.
:books: Freely available programming books
Pros of free-programming-books
- Extensive collection of free programming resources across various languages and topics
- Regularly updated with community contributions, ensuring up-to-date content
- Includes resources in multiple languages, making it accessible to a global audience
Cons of free-programming-books
- Lacks interactive coding exercises or challenges for hands-on practice
- No structured learning path or curriculum, which may be overwhelming for beginners
- Limited to curated links, without original content or explanations
Code comparison
Not applicable, as free-programming-books is a curated list of resources and does not contain code examples. interactive-coding-challenges, on the other hand, provides coding exercises with solutions. For example:
# Example from interactive-coding-challenges
class Node(object):
def __init__(self, data):
self.data = data
self.next = None
class LinkedList(object):
def __init__(self, head=None):
self.head = head
free-programming-books focuses on providing links to external resources rather than code snippets or exercises.
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
Pros of javascript-algorithms
- Focuses specifically on JavaScript, making it ideal for web developers
- Includes implementations of various data structures alongside algorithms
- Provides explanations and complexity analysis for each algorithm
Cons of javascript-algorithms
- Limited to JavaScript, whereas interactive-coding-challenges covers multiple languages
- Lacks interactive coding exercises and unit tests for practice
- Does not include system design or behavioral interview preparation materials
Code Comparison
interactive-coding-challenges (Python):
class Node(object):
def __init__(self, data):
self.data = data
self.next = None
class LinkedList(object):
def __init__(self, head=None):
self.head = head
javascript-algorithms (JavaScript):
class LinkedListNode {
constructor(value, next = null) {
this.value = value;
this.next = next;
}
}
class LinkedList {
constructor() {
this.head = null;
this.tail = null;
}
}
Both repositories provide implementations of common data structures and algorithms. However, interactive-coding-challenges offers a more comprehensive approach to interview preparation, covering multiple languages and including interactive exercises. On the other hand, javascript-algorithms provides a focused resource for JavaScript developers, with detailed explanations and complexity analysis for each algorithm.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
interactive-coding-challenges
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.
Challenge Solutions
Anki Flashcards: Coding and Design
The provided Anki flashcard deck uses spaced repetition to help you retain key concepts.
Great for use while on-the-go.
Design Resource: The System Design Primer
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:
Notebook Structure
Each challenge has two notebooks, a challenge notebook with unit tests 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.
Hints
- [Challenge Notebook] Provides on-demand incremental hints to help you arrive at the optimal solution. Coming soon!
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).
Index
Challenges Categories
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
Reference Implementations: Data Structures
Unit tested, fully functional implementations of the following data structures:
Reference Implementations: Algorithms
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
Reference Implementations: TODO
- A*
- Bellman-Ford
- Bloom Filter
- Convex Hull
- Fisher-Yates Shuffle
- Kruskal's
- Max Flow
- Prim's
- Rabin-Karp
- Traveling Salesman
- Union Find
- Contribute
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 |
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 |
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 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 |
Graphs and Trees
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 |
Sorting
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 |
Recursion and Dynamic Programming
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 |
Mathematics and Probability
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 |
Bit Manipulation
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 |
Online Judges
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 |
Repo Structure
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.
Notebook Installation
Zero Install
This README contains links to Binder , which hosts dynamic notebooks of the repo's contents online with no installation needed.
Jupyter Notebook
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.
Running Challenges
Notebooks
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.
Future Development
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!
Contributing
Contributions are welcome!
Review the Contributing Guidelines for details on how to:
- Submit issues
- Add solutions to existing challenges
- Add new challenges
Credits
Resources
- Cracking the Coding Interview | GitHub Solutions
- Programming Interviews Exposed
- The Algorithm Design Manual | Solutions
- CareerCup
- Quora
- HackerRank
- LeetCode
Images
- 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
Contact Info
Feel free to contact me to discuss any issues, questions, or comments.
My contact info can be found on my GitHub page.
License
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.
Top Related Projects
Interactive roadmaps, guides and other educational content to help developers grow in their careers.
A complete computer science study plan to become a software engineer.
💯 Curated coding interview preparation materials for busy software engineers
All Algorithms implemented in Python
:books: Freely available programming books
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot