Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sagivo/algorithms

algorithms playground for common questions
https://github.com/sagivo/algorithms

algorithm computer-science interview-questions ruby

Last synced: 26 days ago
JSON representation

algorithms playground for common questions

Awesome Lists containing this project

README

        

Algorithms
==========

Algorithms playground for common questions solved in ruby syntax.
In case you want to prepare yourself for a job interview - try to solve it yourself first, then have a look here.

# Why?
I interviewed with [Google](https://github.com/sagivo/algorithms/blob/master/src/google-interview-tips.md), [Facebook](https://github.com/sagivo/algorithms/blob/master/src/facebook-interview-tips.md), [LinkedIn](https://github.com/sagivo/algorithms/blob/master/src/linkedin-interview.md), Twitter and others. I also interviewed others myself.
Sometimes it looks like they all ask you the same "out of the box" questions that don't really check knowledge but memorization of the same tricks.
This is my way of saying - change your interview style. There are lots of smart people out there, this is not the best way to find them.

# Problems

| problem | solution |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unique binary search trees](https://leetcode.com/problems/unique-binary-search-trees/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/unique_bsts.rb) |
| [House Robber](https://leetcode.com/problems/house-robber/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/house-robber.rb) |
| [Decode Ways](https://leetcode.com/problems/decode-ways) | [click](https://github.com/sagivo/algorithms/blob/master/src/decode_ways.rb) |
| [Coin change](https://leetcode.com/problems/coin-change/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/coin-change.rb) |
| [Decode Strings](https://leetcode.com/problems/decode-string/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/decode_string.rb) |
| [Wiggle Subsequence](https://leetcode.com/problems/wiggle-subsequence/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/wiggle_subsequence.rb) |
| [Binary Tree Side View](https://leetcode.com/problems/binary-tree-right-side-view/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/binary_tree_side_view.rb) |
| [Unix path](https://leetcode.com/problems/simplify-path/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/simplify_path.rb) |
| [Array Product](https://leetcode.com/problems/product-of-array-except-self/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/product-of-array.rb) |
| [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/top-k-elements.rb) |
| [Sum 4 arrays](https://leetcode.com/problems/4sum-ii/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/4-sum.rb) |
| [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/reverse-linked-list.rb) |
| [Reverse String In-place](https://leetcode.com/problems/reverse-string/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/reverse-string-inplace.rb) |
| [Nested List Weight Sum II](https://leetcode.com/problems/nested-list-weight-sum-ii/) | [click](https://github.com/sagivo/algorithms/blob/master/src/nested_list_weight_sum_ii.rb) |
| [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [click](https://github.com/sagivo/algorithms/blob/master/src/mirror.rb) |
| [Dijkstra's shortest path between two nodes](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/dijkstra.rb) |
| [Kruskal's minimum spanning tree algorithm](http://en.wikipedia.org/wiki/Kruskal%27s_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/kruskal.rb) |
| [Find the square root of a number](https://en.wikipedia.org/wiki/Newton%27s_method) | [click](https://github.com/sagivo/algorithms/blob/master/src/sq_root.rb) |
| [Add two binary numbers](https://leetcode.com/problems/add-binary/description/) | [click](https://github.com/sagivo/algorithms/blob/master/src/add_binary.rb) |
| [Binary search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/binary_search.rb) |
| [Longest increasing subsequence](http://en.wikipedia.org/wiki/Longest_increasing_subsequence) | [click](https://github.com/sagivo/algorithms/blob/master/src/longest_increasing_subsequence.rb) |
| [Find all permutations of array](https://en.wikipedia.org/wiki/Permutation) | [click](https://github.com/sagivo/algorithms/blob/master/src/permutations.rb) |
| [Finding all combinations of well-formed brackets](http://stackoverflow.com/questions/727707/finding-all-combinations-of-well-formed-brackets) | [click](https://github.com/sagivo/algorithms/blob/master/src/brackets_combinations.rb) |
| [Finding the powerset of a set](http://en.wikipedia.org/wiki/Power_set) | [click](https://github.com/sagivo/algorithms/blob/master/src/powerset.rb) |
| [Game of life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) | [click](https://github.com/sagivo/algorithms/blob/master/src/game_of_life.rb) |
| Print all combinations of set joining | [click](https://github.com/sagivo/algorithms/blob/master/src/join_sets.rb) |
| [count and say](https://leetcode.com/problems/count-and-say/) | [click](https://github.com/sagivo/algorithms/blob/master/src/count_and_say.rb) |
| [Telephone number to words](http://www.mobilefish.com/services/phonenumber_words/phonenumber_words.php) | [click](https://github.com/sagivo/algorithms/blob/master/src/phone.rb) |
| [Maximum contiguous subarray](https://leetcode.com/problems/maximum-subarray) | [click](https://github.com/sagivo/algorithms/blob/master/src/max_subarray.rb) |
| [Max Stack](https://leetcode.com/problems/max-stack/submissions/) | [click](https://github.com/sagivo/algorithms/blob/master/src/max_stack.rb) |
| [Find the smallest biggest number that has the same digits](http://stackoverflow.com/questions/9368205/given-a-number-find-the-next-higher-number-which-has-the-exact-same-set-of-digi) | [click](https://github.com/sagivo/algorithms/blob/master/src/bigger_num_with_same_digits.rb) |
| [Find the minimum insertions needed to make a word palindrome](http://www.geeksforgeeks.org/dynamic-programming-set-28-minimum-insertions-to-form-a-palindrome/) | [click](https://github.com/sagivo/algorithms/blob/master/src/min_insertions_for_palindrome.rb) |
| [String matching - Knuth Morris Pratt algorithm KMP](http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/kmp.rb) |
| [Balanced Parentheses](http://stackoverflow.com/questions/14930073/how-to-check-if-a-string-is-balanced) | [click](https://github.com/sagivo/algorithms/blob/master/src/balanced_parentheses.rb) |
| [Quicksort algorithm](http://en.wikipedia.org/wiki/Quicksort) | [click](https://github.com/sagivo/algorithms/blob/master/src/quicksort.rb) |
| [Mergesort algorithm](https://en.wikipedia.org/wiki/Merge_sort) | [click](https://github.com/sagivo/algorithms/blob/master/src/merge_sort.rb) |
| [Max Stocks Profit](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | [click](https://github.com/sagivo/algorithms/blob/master/src/stocks.rb) |
| [Countingsort algorithm](http://en.wikipedia.org/wiki/Counting_sort) | [click](https://github.com/sagivo/algorithms/blob/master/src/counting_sort.rb) |
| [Shellsort algorithm](http://en.wikipedia.org/wiki/Shellsort) | [click](https://github.com/sagivo/algorithms/blob/master/src/shell_sort.rb) |
| [Knapsack problem](http://en.wikipedia.org/wiki/Knapsack_problem) | [click](https://github.com/sagivo/algorithms/blob/master/src/knapsack.rb), [click](https://github.com/sagivo/algorithms/blob/master/src/knapsack2.rb) |
| [Move Zeroes](https://leetcode.com/problems/move-zeroes) | [click](https://github.com/sagivo/algorithms/blob/master/src/move_zeroes.rb) |
| [Longest common subsequence problem](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) | [click](https://github.com/sagivo/algorithms/blob/master/src/longest_common_subsequence.rb) , [click](https://github.com/sagivo/algorithms/blob/master/src/longest_increasing_subsequence.rb) |
| [Monty Hall Problem](https://en.wikipedia.org/wiki/Monty_hall_problem) | [click](https://github.com/sagivo/algorithms/blob/master/src/monty_hall.rb) |
| [Eucliden and Extended Eucliden algorithm](http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/gcd.rb) |
| Suggest index of a number in an array | [click](https://github.com/sagivo/algorithms/blob/master/src/sugget_index_in_array.rb) |
| [Range minimum query sparse table algorithm](http://en.wikipedia.org/wiki/Range_minimum_query) | [click](https://github.com/sagivo/algorithms/blob/master/src/rmq.rb) |
| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [click](https://github.com/sagivo/algorithms/blob/master/src/insertion_sort.rb) |
| [Towers of Hanoi using Stack](https://en.wikipedia.org/wiki/Tower_of_Hanoi) | [click](blob/master/src/towers_of_hanoi_with_stack.rb)
| [Tarjan's strongly connected components finder](https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm) | [click](https://github.com/sagivo/algorithms/blob/master/src/tarjan.rb) |

# How?
Simply run `ruby some_file.rb` to execute the algorithm. At the bottom of each file there are some test samples.
example: `ruby brackets_combinations.rb` will print:
`["((()))", "(()())", "(())()", "()(())", "()()()"]`.

# Contribute
Did you find a bug? any way to do it better? please feel free to pull-request it :)