mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
167 lines
11 KiB
Markdown
167 lines
11 KiB
Markdown
<p align="center">
|
|
<img src="http://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif">
|
|
<br/>
|
|
<i>Wikipedia: Quicksort</i>
|
|
</p>
|
|
|
|
algorithms-data-structures
|
|
============
|
|
|
|
Continually updated IPython Notebooks containing coding problems and solutions (algorithms and data structures).
|
|
|
|
This repo is a collection of my notes while sharpening my skills tackling coding problems.
|
|
|
|
## Index
|
|
|
|
* [Arrays and Strings](#arrays-and-strings)
|
|
* [Linked Lists](#linked-lists)
|
|
* [Stacks and Queues](#stacks-and-queues)
|
|
* [Sorting and Searching](#sorting-and-searching)
|
|
* [Recursion and Dynamic Programming](#recursion-and-dynamic-programming)
|
|
* [Trees and Graphs](#trees-and-graphs)
|
|
* [Bit Manipulation](#bit-manipulation)
|
|
* [Scalability and Memory Limits](#scalability-and-memory-limits)
|
|
* [Concurrency](#concurrency)
|
|
* [Hacker Rank and TopCoder](#hackerrank-and-topcoder)
|
|
* [Notebook Installation](#notebook-installation)
|
|
* [Credits](#credits)
|
|
* [Contact Info](#contact-info)
|
|
* [License](#license)
|
|
|
|
## Arrays and Strings
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [unique_chars](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/unique_chars.ipynb) | Determine if a string contains unique characters |
|
|
| [reverse_string](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/reverse_string.ipynb) | Reverse characters in a string |
|
|
| [permutation](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/permutation.ipynb) | Determine if a string is a permutation of another |
|
|
| [replace_char](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/replace_char.ipynb) | Encode spaces in a string in-place |
|
|
| [compress](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/compress.ipynb) | Compress a string |
|
|
| [rotation](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/rotation.ipynb) | Determine if a string is a rotation of another |
|
|
| [hash-map](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/arrays-strings/hash-map.ipynb) | Implement a hash table with set, get, and remove methods |
|
|
|
|
## Linked Lists
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [remove-duplicates](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/remove-duplicates.ipynb) | Remove duplicates from a linked list |
|
|
| [kth-to-last-elem](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/kth-to-last-elem.ipynb) | Find the kth to last element of a linked list |
|
|
| [delete-mid](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/delete-mid.ipynb) | Delete a node in the middle of a linked list, given access to only that node |
|
|
| [partition](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/partition.ipynb) | Partition a linked list around a given value |
|
|
| [add-reverse](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/add-reverse.ipynb) | Add two numbers whose digits are stored in a linked list in reverse order |
|
|
| [find-loop-start](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/find-loop-start.ipynb) | Find the start of a linked list loop |
|
|
| [palindrome](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/palindrome.ipynb) | Determine if a linked list is a palindrome |
|
|
| [linked-list](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/linked-lists/linked-list.ipynb) | Implement a linked list with insert, find, delete, and print methods |
|
|
|
|
## Stacks and Queues
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [n-stacks](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/n-stacks.ipynb) | Implement n stacks using a single array |
|
|
| [stack-min](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/stack-min.ipynb) | Implement a stack that keeps track of its minimum element |
|
|
| [set-of-stacks](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/set-of-stacks.ipynb) | Implement a set of stacks class that wraps a list of stacks, each bound by a capacity |
|
|
| [hanoi](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/hanoi.ipynb) | Implement the Towers of Hanoi with 3 towers and N disks |
|
|
| [queue-from-stacks](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/queue-from-stacks.ipynb) | Implement a queue using two stacks |
|
|
| [sort-stack](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/sort-stack.ipynb) | Sort a stack using another stack as a buffer |
|
|
| [stack](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/stack.ipynb) | Implement a stack with push, pop, and peek methods using a linked list |
|
|
| [queue](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/stacks-queues/queue.ipynb) | Implement a queue with enqueue and dequeue methods using a linked list |
|
|
|
|
## Sorting and Searching
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [selection-sort](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/sorting-searching/selection-sort.ipynb#) | Implement selection sort |
|
|
| [insertion-sort](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/sorting-searching/insertion-sort.ipynb#) | Implement insertion sort |
|
|
| [quick-sort](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/sorting-searching/quick-sort.ipynb#) | Implement quick sort |
|
|
| [merge-sort](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/sorting-searching/merge-sort.ipynb#) | Implement merge sort |
|
|
|
|
## Recursion and Dynamic Programming
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [fibonacci](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/recursion-dynamic/fibonacci.ipynb#) | Implement fibonacci recursively, dynamically, and iteratively |
|
|
|
|
## Trees and Graphs
|
|
|
|
[Coming Soon]
|
|
|
|
## Bit Manipulation
|
|
|
|
[Coming Soon]
|
|
|
|
## Scalability and Memory Limits
|
|
|
|
[Coming Soon]
|
|
|
|
## Concurrency
|
|
|
|
[Coming Soon]
|
|
|
|
## HackerRank and TopCoder
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [utopian-tree](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/hacker-rank/utopian-tree.ipynb) | [View problem statement on HackerRank](https://www.hackerrank.com/challenges/utopian-tree) |
|
|
| [maximizing-xor](http://nbviewer.ipython.org/github/donnemartin/algorithms-data-structures/blob/master/hacker-rank/maximizing-xor.ipynb) | [View problem statement on HackerRank](https://www.hackerrank.com/challenges/maximizing-xor) |
|
|
|
|
## Notebook Installation
|
|
|
|
If you already have Python installed and are familiar with installing packages, you can get IPython with pip:
|
|
|
|
```
|
|
pip install ipython
|
|
```
|
|
|
|
Or if you want to also get the dependencies for the IPython notebook:
|
|
|
|
```
|
|
pip install "ipython[notebook]"
|
|
```
|
|
|
|
For more details on installation, follow the directions [here.](http://ipython.org/install.html)
|
|
|
|
To interact with or to modify elements within the IPython notebooks, you must first clone or download the repository then run the ipython notebook. More information on IPython Notebooks can be found [here.](http://ipython.org/notebook.html)
|
|
|
|
```
|
|
$ git clone https://github.com/donnemartin/algorithms-data-structures.git
|
|
$ cd [downloaded repo directory name]
|
|
$ ipython notebook
|
|
```
|
|
|
|
Notebook tested with Python 2.7.x.
|
|
|
|
## Credits
|
|
|
|
* [Cracking the Coding Interview](http://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/098478280X) | [GitHub](https://github.com/gaylemcd/ctci)
|
|
* [Elements of Programming Interviews](http://www.amazon.com/Elements-Programming-Interviews-Insiders-Guide/dp/1479274836) | [GitHub](https://github.com/epibook/epibook.github.io)
|
|
* [Programming Interviews Exposed](http://www.amazon.com/gp/product/1118261364/)
|
|
* [The Algorithm Design Manual](http://www.amazon.com/Algorithm-Design-Manual-Steve-Skiena/dp/0387948600) | [Selected Solutions](http://www.algorithm.cs.sunysb.edu/algowiki/index.php/The_Algorithms_Design_Manual_(Second_Edition))
|
|
* [HackerRank](https://www.hackerrank.com)
|
|
* [TopCoder](https://www.topcoder.com/)
|
|
|
|
## Contact Info
|
|
|
|
Feel free to contact me to discuss any issues, questions, or comments.
|
|
|
|
* Email: [donne.martin@gmail.com](mailto:donne.martin@gmail.com)
|
|
* Twitter: [@donne_martin](https://twitter.com/donne_martin)
|
|
* GitHub: [donnemartin](https://github.com/donnemartin)
|
|
* LinkedIn: [donnemartin](https://www.linkedin.com/in/donnemartin)
|
|
* Website: [donnemartin.com](http://donnemartin.com)
|
|
|
|
## License
|
|
|
|
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.
|