Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

donnemartin/interactive-coding-challenges

Repository files navigation


interactive-coding-challenges

Binder

120+ continually updated, interactive, and test-driven coding challenges, withAnki flashcards.

Challenges focus onalgorithms anddata structures found incoding interviews.

Each challenge has one or more reference solutions that are:

  • Fully functional
  • Unit tested
  • Easy-to-understand

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

Notebooks also detail:

  • Constraints
  • Test cases
  • Algorithms
  • Big-O time and space complexities

Also included areunit tested reference implementations of variousdata structures andalgorithms.

Challenge Solutions



Anki Flashcards: Coding and Design


The providedAnki 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 theSystem Design andObject-Oriented Design interviews?


Check out the sister repoThe System Design Primer, which contains additional Anki decks:

Notebook Structure

Each challenge has two notebooks, achallenge notebook with unit tests for you to solve and asolution 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-demandincremental 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 charactersChallengeSolution
Determine if a string is a permutation of anotherChallengeSolution
Determine if a string is a rotation of anotherChallengeSolution
Compress a stringChallengeSolution
Reverse characters in a stringChallengeSolution
Given two strings, find the single different charChallengeSolution
Find two indices that sum to a specific valueChallengeSolution
Implement a hash tableChallengeSolution
Implement fizz buzzChallengeSolution
Find the first non-repeated character in a stringContributeContribute
Remove specified characters in a stringContributeContribute
Reverse words in a stringContributeContribute
Convert a string to an integerContributeContribute
Convert an integer to a stringContributeContribute
Add a challengeContributeContribute


Linked Lists

Binder

ChallengeStatic Notebook
Remove duplicates from a linked listChallengeSolution
Find the kth to last element of a linked listChallengeSolution
Delete a node in the middle of a linked listChallengeSolution
Partition a linked list around a given valueChallengeSolution
Add two numbers whose digits are stored in a linked listChallengeSolution
Find the start of a linked list loopChallengeSolution
Determine if a linked list is a palindromeChallengeSolution
Implement a linked listChallengeSolution
Determine if a list is cyclic or acyclicContributeContribute
Add a challengeContributeContribute


Stacks and Queues

Binder

ChallengeStatic Notebook
Implement n stacks using a single arrayChallengeSolution
Implement a stack that keeps track of its minimum elementChallengeSolution
Implement a set of stacks class that wraps a list of capacity-bounded stacksChallengeSolution
Implement a queue using two stacksChallengeSolution
Sort a stack using another stack as a bufferChallengeSolution
Implement a stackChallengeSolution
Implement a queueChallengeSolution
Implement a priority queue backed by an arrayChallengeSolution
Add a challengeContributeContribute


Graphs and Trees

Binder

ChallengeStatic Notebooks
Implement depth-first search (pre-, in-, post-order) on a treeChallengeSolution
Implement breadth-first search on a treeChallengeSolution
Determine the height of a treeChallengeSolution
Create a binary search tree with minimal height from a sorted arrayChallengeSolution
Create a linked list for each level of a binary treeChallengeSolution
Check if a binary tree is balancedChallengeSolution
Determine if a tree is a valid binary search treeChallengeSolution
Find the in-order successor of a given node in a binary search treeChallengeSolution
Find the second largest node in a binary search treeChallengeSolution
Find the lowest common ancestorChallengeSolution
Invert a binary treeChallengeSolution
Implement a binary search treeChallengeSolution
Implement a min heapChallengeSolution
Implement a trieChallengeSolution
Implement depth-first search on a graphChallengeSolution
Implement breadth-first search on a graphChallengeSolution
Determine if there is a path between two nodes in a graphChallengeSolution
Implement a graphChallengeSolution
Find a build order given a list of projects and dependencies.ChallengeSolution
Find the shortest path in a weighted graph.ChallengeSolution
Find the shortest path in an unweighted graph.ChallengeSolution
Add a challengeContributeContribute


Sorting

Binder

ChallengeStatic Notebooks
Implement selection sortChallengeSolution
Implement insertion sortChallengeSolution
Implement quick sortChallengeSolution
Implement merge sortChallengeSolution
Implement radix sortChallengeSolution
Sort an array of strings so all anagrams are next to each otherChallengeSolution
Find an item in a sorted, rotated arrayChallengeSolution
Search a sorted matrix for an itemChallengeSolution
Find an int not in an input of n integersChallengeSolution
Given sorted arrays A, B, merge B into A in sorted orderChallengeSolution
Implement a stable selection sortContributeContribute
Make an unstable sort stableContributeContribute
Implement an efficient, in-place version of quicksortContributeContribute
Given two sorted arrays, merge one into the other in sorted orderContributeContribute
Find an element in a rotated and sorted array of integersContributeContribute
Add a challengeContributeContribute


Recursion and Dynamic Programming

Binder

ChallengeStatic Notebooks
Implement fibonacci recursively, dynamically, and iterativelyChallengeSolution
Maximize items placed in a knapsackChallengeSolution
Maximize unbounded items placed in a knapsackChallengeSolution
Find the longest common subsequenceChallengeSolution
Find the longest increasing subsequenceChallengeSolution
Minimize the cost of matrix multiplicationChallengeSolution
Maximize stock prices given k transactionsChallengeSolution
Find the minimum number of ways to represent n cents given an array of coinsChallengeSolution
Find the unique number of ways to represent n cents given an array of coinsChallengeSolution
Print all valid combinations of n-pairs of parenthesesChallengeSolution
Navigate a mazeChallengeSolution
Print all subsets of a setChallengeSolution
Print all permutations of a stringChallengeSolution
Find the magic index in an arrayChallengeSolution
Find the number of ways to run up n stepsChallengeSolution
Implement the Towers of Hanoi with 3 towers and N disksChallengeSolution
Implement factorial recursively, dynamically, and iterativelyContributeContribute
Perform a binary search on a sorted array of integersContributeContribute
Print all combinations of a stringContributeContribute
Implement a paint fill functionContributeContribute
Find all permutations to represent n cents, given 1, 5, 10, 25 cent coinsContributeContribute
Add a challengeContributeContribute


Mathematics and Probability

Binder

ChallengeStatic Notebooks
Generate a list of primesChallengeSolution
Find the digital rootChallengeSolution
Create a class supporting insert, max, min, mean, mode in O(1)ChallengeSolution
Determine if a number is a power of twoChallengeSolution
Add two numbers without the + or - signChallengeSolution
Subtract two numbers without the + or - signChallengeSolution
Check if a number is primeContributeContribute
Determine if two lines on a Cartesian plane intersectContributeContribute
Using only add, implement multiply, subtract, and divide for intsContributeContribute
Find the kth number such that the only prime factors are 3, 5, and 7ContributeContribute
Add a challengeContributeContribute


Bit Manipulation

Binder

ChallengeStatic Notebooks
Implement common bit manipulation operationsChallengeSolution
Determine number of bits to flip to convert a into bChallengeSolution
Draw a line on a screenChallengeSolution
Flip a bit to maximize the longest sequence of 1sChallengeSolution
Get the next largest and next smallest numbersChallengeSolution
Merge two binary numbersChallengeSolution
Swap odd and even bits in an integerChallengeSolution
Print the binary representation of a number between 0 and 1ChallengeSolution
Determine the number of 1s in the binary representation of a given integerContributeContribute
Add a challengeContributeContribute


Online Judges

Binder

ChallengeStatic Notebooks
Find the longest substring with at most k distinct charsChallengeSolution
Find the highest product of three numbersChallengeSolution
Maximize stocks profit from 1 buy and 1 sellChallengeSolution
Move all zeroes in a list to the endChallengeSolution
Find the products of every other intChallengeSolution
Given a list of entries and exits, find the busiest periodChallengeSolution
Determine an island's perimeterChallengeSolution
Format license keysChallengeSolution
Find the longest absolute file pathChallengeSolution
Merge tuple rangesChallengeSolution
Assign cookiesChallengeSolution
Determine if you can win in NimChallengeSolution
Check if a magazine could have been used to create a ransom noteChallengeSolution
Find the number of times a sentence can fit on a screenChallengeSolution
Utopian treeChallengeSolution
Maximizing xorChallengeSolution
Add a challengeContributeContribute

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 toBinder , which hostsdynamic 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 thedev-setup repo.

For more details on notebook installation, follow the directionshere.

More information on IPython/Jupyter Notebooks can be foundhere.

Running Challenges

Notebooks

Challenges are provided in the form ofIPython/Jupyter Notebooks and have beentested with Python 2.7 and Python 3.x.

If you need to install IPython/Jupyter Notebook, see theNotebook Installation section.

  • This README contains links tonbviewer, which hostsstatic notebooks of the repo's contents
  • To interact with or to modify elements within thedynamic 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 theChallenge 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 accompanyingSolution Notebook for further discussion

Todebug your solution with pdb, refer to the followingticket.

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 theContributing Guidelines for details.

Future Development

Challenges, solutions, and unit tests are presented in the form ofIPython/Jupyter Notebooks.

  • Notebooks currently contain mostly Python solutions (tested on both Python 2.7 and Python 3.x), but can be extended to include40+ supported languages
  • Repo will becontinually updated with new solutions and challenges
  • Contributions are welcome!

Contributing

Contributions are welcome!

Review theContributing 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 myGitHub 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 MartinLicensed 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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors41

Languages


[8]ページ先頭

©2009-2025 Movatter.jp