mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
176 lines
12 KiB
Markdown
176 lines
12 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>
|
|
|
|
coding-challenges
|
|
============
|
|
|
|
Continually updated Python Notebooks containing TDD-based coding challenges and solutions (algorithms and data structures).
|
|
|
|
## 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)
|
|
* [HackerRank and TopCoder](#hackerrank-and-topcoder)
|
|
* [Notebook Installation](#notebook-installation)
|
|
* [Credits](#credits)
|
|
* [Contributing](#contributing)
|
|
* [Contact Info](#contact-info)
|
|
* [License](#license)
|
|
|
|
## Arrays and Strings
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [unique_chars](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/unique_chars/unique_chars_solution.ipynb) | Determine if a string contains unique characters |
|
|
| [reverse_string](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/reverse_string/reverse_string_solution.ipynb) | Reverse characters in a string |
|
|
| [permutation](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/permutation/permutation_solution.ipynb) | Determine if a string is a permutation of another |
|
|
| [replace_char](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/replace_char/replace_char_solution.ipynb) | Encode spaces in a string in-place |
|
|
| [compress](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/compress/compress_solution.ipynb) | Compress a string |
|
|
| [rotation](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/rotation/rotation_solution.ipynb) | Determine if a string is a rotation of another |
|
|
| [hash-map](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/arrays_strings/hash_map/hash_map_solution.ipynb) | Implement a hash table with set, get, and remove methods |
|
|
|
|
## Linked Lists
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [remove_duplicates](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb) | Remove duplicates from a linked list |
|
|
| [kth_to_last_elem](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/kth_to_last_elem/kth_to_last_elem_solution.ipynb) | Find the kth to last element of a linked list |
|
|
| [delete_mid](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/delete_mid/delete_mid_solution.ipynb) | Delete a node in the middle of a linked list, given access to only that node |
|
|
| [partition](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/partition/partition_solution.ipynb) | Partition a linked list around a given value |
|
|
| [add_reverse](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/add_reverse/add_reverse_solution.ipynb) | Add two numbers whose digits are stored in a linked list in reverse order |
|
|
| [find_loop_start](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/find_loop_start/find_loop_start_solution.ipynb) | Find the start of a linked list loop |
|
|
| [palindrome](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/palindrome/palindrome_solution.ipynb) | Determine if a linked list is a palindrome |
|
|
| [linked_list](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/linked_lists/linked_list/linked_list_solution.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/coding-challenges/blob/master/stacks_queues/n_stacks/n_stacks_solution.ipynb) | Implement n stacks using a single array |
|
|
| [stack_min](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/stacks_queues/stack_min/stack_min_solution.ipynb) | Implement a stack that keeps track of its minimum element |
|
|
| [set_of_stacks](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/stacks_queues/set_of_stacks/set_of_stacks_solution.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/coding-challenges/blob/master/stacks_queues/hanoi/hanoi_solution.ipynb) | Implement the Towers of Hanoi with 3 towers and N disks |
|
|
| [queue_from_stacks](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/stacks_queues/queue_from_stacks/queue_from_stacks_solution.ipynb) | Implement a queue using two stacks |
|
|
| [sort_stack](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/stacks_queues/sort_stack/sort_stack_solution.ipynb) | Sort a stack using another stack as a buffer |
|
|
| [stack](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/stacks_queues/stack/stack_solution.ipynb) | Implement a stack with push, pop, and peek methods using a linked list |
|
|
| [queue](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/stacks_queues/queue_list/queue_list_solution.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/coding-challenges/blob/master/sorting_searching/selection_sort/selection_sort_solution.ipynb#) | Implement selection sort |
|
|
| [insertion_sort](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/sorting_searching/insertion_sort/insertion_sort_solution.ipynb#) | Implement insertion sort |
|
|
| [quick_sort](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/sorting_searching/quick_sort/quick_sort_solution.ipynb#) | Implement quick sort |
|
|
| [merge_sort](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/sorting_searching/merge_sort/merge_sort_solution.ipynb#) | Implement merge sort |
|
|
|
|
## Recursion and Dynamic Programming
|
|
|
|
| Notebook | Problem Statement |
|
|
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| [fibonacci](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/recursion_dynamic/fibonacci/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/coding-challenges/blob/master/hackerrank_topcoder/utopian_tree/utopian_tree.ipynb) | [View problem statement on HackerRank](https://www.hackerrank.com/challenges/utopian-tree) |
|
|
| [maximizing_xor](http://nbviewer.ipython.org/github/donnemartin/coding-challenges/blob/master/hackerrank_topcoder/maximizing_xor/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/coding-challenges.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))
|
|
* [CareerCup](http://www.careercup.com/)
|
|
* [Quora](http://www.quora.com/)
|
|
* [HackerRank](https://www.hackerrank.com)
|
|
* [TopCoder](https://www.topcoder.com/)
|
|
|
|
## Contributing
|
|
|
|
Contributions are welcome!
|
|
|
|
For bug reports or requests please [submit an issue](https://github.com/donnemartin/data-science-ipython-notebooks/issues).
|
|
|
|
For pull requests, please follow the general notebook format.
|
|
|
|
## 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.
|