Convert Figma logo to code with AI

donnemartin logointeractive-coding-challenges

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.

29,429
4,447
29,429
73

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

191,495

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:

  1. Clone the repository:

    git clone https://github.com/donnemartin/interactive-coding-challenges.git
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    
  3. Launch Jupyter Notebook:

    jupyter notebook
    
  4. 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.

191,495

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


interactive-coding-challenges

Binder

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

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:

Reference Implementations: TODO

Installing and Running Challenges

Misc

Challenges

Image Credits



Arrays and Strings

Binder

ChallengeStatic Notebook
Determine if a string contains unique charactersChallenge │ Solution
Determine if a string is a permutation of anotherChallenge │ Solution
Determine if a string is a rotation of anotherChallenge │ Solution
Compress a stringChallenge │ Solution
Reverse characters in a stringChallenge │ Solution
Given two strings, find the single different charChallenge │ Solution
Find two indices that sum to a specific valueChallenge │ Solution
Implement a hash tableChallenge │ Solution
Implement fizz buzzChallenge │ Solution
Find the first non-repeated character in a stringContribute │ Contribute
Remove specified characters in a stringContribute │ Contribute
Reverse words in a stringContribute │ Contribute
Convert a string to an integerContribute │ Contribute
Convert an integer to a stringContribute │ Contribute
Add a challengeContribute │ Contribute


Linked Lists

Binder

ChallengeStatic Notebook
Remove duplicates from a linked listChallenge │ Solution
Find the kth to last element of a linked listChallenge │ Solution
Delete a node in the middle of a linked listChallenge │ Solution
Partition a linked list around a given valueChallenge │ Solution
Add two numbers whose digits are stored in a linked listChallenge │ Solution
Find the start of a linked list loopChallenge │ Solution
Determine if a linked list is a palindromeChallenge │ Solution
Implement a linked listChallenge │ Solution
Determine if a list is cyclic or acyclicContribute │ Contribute
Add a challengeContribute │ Contribute


Stacks and Queues

Binder

ChallengeStatic Notebook
Implement n stacks using a single arrayChallenge │ Solution
Implement a stack that keeps track of its minimum elementChallenge │ Solution
Implement a set of stacks class that wraps a list of capacity-bounded stacksChallenge │ Solution
Implement a queue using two stacksChallenge │ Solution
Sort a stack using another stack as a bufferChallenge │ Solution
Implement a stackChallenge │ Solution
Implement a queueChallenge │ Solution
Implement a priority queue backed by an arrayChallenge │ Solution
Add a challengeContribute │ Contribute


Graphs and Trees

Binder

ChallengeStatic Notebooks
Implement depth-first search (pre-, in-, post-order) on a treeChallenge │ Solution
Implement breadth-first search on a treeChallenge │ Solution
Determine the height of a treeChallenge │ Solution
Create a binary search tree with minimal height from a sorted arrayChallenge │ Solution
Create a linked list for each level of a binary treeChallenge │ Solution
Check if a binary tree is balancedChallenge │ Solution
Determine if a tree is a valid binary search treeChallenge │ Solution
Find the in-order successor of a given node in a binary search treeChallenge │ Solution
Find the second largest node in a binary search treeChallenge │ Solution
Find the lowest common ancestorChallenge │ Solution
Invert a binary treeChallenge │ Solution
Implement a binary search treeChallenge │ Solution
Implement a min heapChallenge │ Solution
Implement a trieChallenge │ Solution
Implement depth-first search on a graphChallenge │ Solution
Implement breadth-first search on a graphChallenge │ Solution
Determine if there is a path between two nodes in a graphChallenge │ Solution
Implement a graphChallenge │ 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 challengeContribute │ Contribute


Sorting

Binder

ChallengeStatic Notebooks
Implement selection sortChallenge │ Solution
Implement insertion sortChallenge │ Solution
Implement quick sortChallenge │ Solution
Implement merge sortChallenge │ Solution
Implement radix sortChallenge │ Solution
Sort an array of strings so all anagrams are next to each otherChallenge │ Solution
Find an item in a sorted, rotated arrayChallenge │ Solution
Search a sorted matrix for an itemChallenge │ Solution
Find an int not in an input of n integersChallenge │ Solution
Given sorted arrays A, B, merge B into A in sorted orderChallenge │ Solution
Implement a stable selection sortContribute │ Contribute
Make an unstable sort stableContribute │ Contribute
Implement an efficient, in-place version of quicksortContribute │ Contribute
Given two sorted arrays, merge one into the other in sorted orderContribute │ Contribute
Find an element in a rotated and sorted array of integersContribute │ Contribute
Add a challengeContribute │ Contribute


Recursion and Dynamic Programming

Binder

ChallengeStatic Notebooks
Implement fibonacci recursively, dynamically, and iterativelyChallenge │ Solution
Maximize items placed in a knapsackChallenge │ Solution
Maximize unbounded items placed in a knapsackChallenge │ Solution
Find the longest common subsequenceChallenge │ Solution
Find the longest increasing subsequenceChallenge │ Solution
Minimize the cost of matrix multiplicationChallenge │ Solution
Maximize stock prices given k transactionsChallenge │ Solution
Find the minimum number of ways to represent n cents given an array of coinsChallenge │ Solution
Find the unique number of ways to represent n cents given an array of coinsChallenge │ Solution
Print all valid combinations of n-pairs of parenthesesChallenge │ Solution
Navigate a mazeChallenge │ Solution
Print all subsets of a setChallenge │ Solution
Print all permutations of a stringChallenge │ Solution
Find the magic index in an arrayChallenge │ Solution
Find the number of ways to run up n stepsChallenge │ Solution
Implement the Towers of Hanoi with 3 towers and N disksChallenge │ Solution
Implement factorial recursively, dynamically, and iterativelyContribute │ Contribute
Perform a binary search on a sorted array of integersContribute │ Contribute
Print all combinations of a stringContribute │ Contribute
Implement a paint fill functionContribute │ Contribute
Find all permutations to represent n cents, given 1, 5, 10, 25 cent coinsContribute │ Contribute
Add a challengeContribute │ Contribute


Mathematics and Probability

Binder

ChallengeStatic Notebooks
Generate a list of primesChallenge │ Solution
Find the digital rootChallenge │ Solution
Create a class supporting insert, max, min, mean, mode in O(1)Challenge │ Solution
Determine if a number is a power of twoChallenge │ Solution
Add two numbers without the + or - signChallenge │ Solution
Subtract two numbers without the + or - signChallenge │ Solution
Check if a number is primeContribute │ Contribute
Determine if two lines on a Cartesian plane intersectContribute │ Contribute
Using only add, implement multiply, subtract, and divide for intsContribute │ Contribute
Find the kth number such that the only prime factors are 3, 5, and 7Contribute │ Contribute
Add a challengeContribute │ Contribute


Bit Manipulation

Binder

ChallengeStatic Notebooks
Implement common bit manipulation operationsChallenge │ Solution
Determine number of bits to flip to convert a into bChallenge │ Solution
Draw a line on a screenChallenge │ Solution
Flip a bit to maximize the longest sequence of 1sChallenge │ Solution
Get the next largest and next smallest numbersChallenge │ Solution
Merge two binary numbersChallenge │ Solution
Swap odd and even bits in an integerChallenge │ Solution
Print the binary representation of a number between 0 and 1Challenge │ Solution
Determine the number of 1s in the binary representation of a given integerContribute │ Contribute
Add a challengeContribute │ Contribute


Online Judges

Binder

ChallengeStatic Notebooks
Find the longest substring with at most k distinct charsChallenge │ Solution
Find the highest product of three numbersChallenge │ Solution
Maximize stocks profit from 1 buy and 1 sellChallenge │ Solution
Move all zeroes in a list to the endChallenge │ Solution
Find the products of every other intChallenge │ Solution
Given a list of entries and exits, find the busiest periodChallenge │ Solution
Determine an island's perimeterChallenge │ Solution
Format license keysChallenge │ Solution
Find the longest absolute file pathChallenge │ Solution
Merge tuple rangesChallenge │ Solution
Assign cookiesChallenge │ Solution
Determine if you can win in NimChallenge │ Solution
Check if a magazine could have been used to create a ransom noteChallenge │ Solution
Find the number of times a sentence can fit on a screenChallenge │ Solution
Utopian treeChallenge │ Solution
Maximizing xorChallenge │ Solution
Add a challengeContribute │ 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

Binder

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

Images

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.