interactive-coding-challenges README

The project's README from github.com/donnemartin/interactive-coding-challenges. As one markdown file: README.md.


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:

Challenges will soon provide on-demand incremental hints to help you arrive at the optimal solution.

Notebooks also detail:

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

Constraints

Test Cases

Algorithm

Hints

Code (Challenge: Implement Me!)

Unit Test

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.

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:

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.

Contributing

Contributions are welcome!

Review the Contributing Guidelines for details on how to:

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.

interactive-coding-challenges (donnemartin/interactive-coding-challenges)

Searching Database…

这是什么?这是一套包含 120 多道交互式、测试驱动的 Python 编程挑战,涵盖编程面试中常见的算法与数据结构题。每道题都以 Jupyter 笔记本的形式提供,附带单元测试和配套的解答笔记本,另外还附有一套 Anki 闪卡牌组。
这是一本书、一个教程网站,还是别的什么?它是一组 Jupyter 笔记本。每道题都有一个「challenge」笔记本,里面是待你补全的代码框架和单元测试;同时配有一个「solution」笔记本,包含经过单元测试验证的完整实现。
我该怎样完成一道挑战?打开某个主题对应的挑战笔记本,实现框架中的函数,然后运行附带的单元测试。在你的解答正确之前,测试会失败;如果卡住了,可以对照配套的解答笔记本。
打开这些笔记本除了 Python 还需要别的东西吗?需要。你得先安装 Jupyter,才能打开并运行 .ipynb 文件。仓库中专门有关于笔记本安装和运行挑战的设置说明。
120 多道挑战都已经完整做好了吗?没有。每个分类中都有几道题标注为「Contribute」,没有提供解答,意味着它们仍然开放,等待社区提交。另外,文档中列出的按需提示功能目前尚不可用。
这些挑战是怎样按主题分类的?它们被分成若干类别,包括数组与字符串、链表、栈与队列、图与树、排序、递归与动态规划、数学与概率、位运算、在线评测、系统设计以及面向对象设计等,每类都标明了各自的题目数量。
Anki 闪卡是做什么用的?它们采用间隔重复的方法,帮助你牢记关键的编程与设计概念,适合在路上随时快速复习。
这里是否也涵盖系统设计面试的准备内容?不直接涵盖。仓库指向一个姊妹仓库「The System Design Primer」,那里有专门针对系统设计和面向对象设计练习的 Anki 牌组。
除了挑战题本身,这里还有别的内容吗?有。仓库还附带了一些独立的、经过单元测试的参考实现,包括常见数据结构(如链表、字典树、最小堆等)和算法(如快速排序、Dijkstra 算法、埃拉托斯特尼筛法等)。
Size
7.6 MB
Stars
31.9K
Updated
CommitAug 05
Age
11y
Commits · 90 Days