• Stars
    star
    29,364
  • Rank 621 (Top 0.02 %)
  • Language
    Python
  • License
    Other
  • Created over 9 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

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

Binder

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

Binder

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

Binder

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

Binder

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

Binder

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

Binder

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

Binder

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

Binder

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

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.

More Repositories

1

system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.
Python
270,532
star
2

data-science-ipython-notebooks

Data science Python notebooks: Deep learning (TensorFlow, Theano, Caffe, Keras), scikit-learn, Kaggle, big data (Spark, Hadoop MapReduce, HDFS), matplotlib, pandas, NumPy, SciPy, Python essentials, AWS, and various command lines.
Python
27,165
star
3

awesome-aws

A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Python
12,428
star
4

gitsome

A supercharged Git/GitHub command line interface (CLI). An official integration for GitHub and GitHub Enterprise: https://github.com/works-with/category/desktop-tools
Python
7,570
star
5

dev-setup

macOS development environment setup: Easy-to-understand instructions with automated setup scripts for developer tools like Vim, Sublime Text, Bash, iTerm, Python data analysis, Spark, Hadoop MapReduce, AWS, Heroku, JavaScript web development, Android development, common data stores, and dev-based OS X defaults.
Python
6,117
star
6

saws

A supercharged AWS command line interface (CLI).
Python
5,241
star
7

haxor-news

Browse Hacker News like a haxor: A Hacker News command line interface (CLI).
Python
3,974
star
8

viz

Visualize GitHub's most popular repos. http://www.donnemartin.com/viz
Python
788
star
9

spiders

Web Crawlers.
Python
116
star
10

donnemartin.github.io

Personal website powered by Bootstrap, Pelican, and GitHub Pages. http://donnemartin.com/
HTML
69
star
11

stocks

C++ Stock Analyzer: Analyzes and ranks stocks based on their Moving Average Convergence Divergence (MACD)
C++
66
star
12

elevator-simulator

Simulates four elevators available to take passengers up and down a 100 floor building
C++
65
star
13

notes

Android app for taking notes: Text, photos, audio, photos, and soon videos
Java
53
star
14

google-maps-tracker

Android app to report/track your location using Google Maps API
Java
44
star
15

gitflow

Gitflow sandbox clone.
Shell
28
star
16

photo-gallery

Android Flickr photo gallery Gradle app integrated with Travis CI and the Android Testing Framework
Java
27
star
17

air-pollution

R scripts that analyze sulfate and nitrate pollution data from sensors monitoring fine particulate matter air pollution at 332 locations in the United States.
R
26
star
18

poker

C++ poker hand ranker
C++
23
star
19

hospital-quality

R scripts that analyze and rank hospitals based on mortality rates from the Hospital Compare data run by the U.S. Department of Health and Human Services.
R
23
star
20

dev-setup-resources

Resources referenced from the repo: https://github.com/donnemartin/dev-setup
22
star
21

r-snippets

Various R snippets for reading, subsetting, summarizing, reshaping, merging, and cleaning data
R
19
star
22

gh

Python
10
star
23

sandbox

Hack
8
star