{"id":13395455,"url":"https://github.com/sagivo/algorithms","last_synced_at":"2025-05-15T02:04:12.631Z","repository":{"id":23062086,"uuid":"26415499","full_name":"sagivo/algorithms","owner":"sagivo","description":"algorithms playground for common questions","archived":false,"fork":false,"pushed_at":"2022-08-18T11:55:51.000Z","size":117,"stargazers_count":3258,"open_issues_count":2,"forks_count":355,"subscribers_count":134,"default_branch":"master","last_synced_at":"2025-04-06T19:08:53.171Z","etag":null,"topics":["algorithm","computer-science","interview-questions","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagivo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-10T01:11:42.000Z","updated_at":"2025-03-18T10:09:42.000Z","dependencies_parsed_at":"2022-07-12T06:16:12.740Z","dependency_job_id":null,"html_url":"https://github.com/sagivo/algorithms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagivo%2Falgorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagivo%2Falgorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagivo%2Falgorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagivo%2Falgorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagivo","download_url":"https://codeload.github.com/sagivo/algorithms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790482,"owners_count":21162015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","computer-science","interview-questions","ruby"],"created_at":"2024-07-30T17:01:59.693Z","updated_at":"2025-04-13T22:29:42.584Z","avatar_url":"https://github.com/sagivo.png","language":"Ruby","readme":"Algorithms\n==========\n\nAlgorithms playground for common questions solved in ruby syntax.  \nIn case you want to prepare yourself for a job interview - try to solve it yourself first, then have a look here.  \n\n# Why?\nI 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.\nSometimes 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.\nThis 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.\n\n# Problems\n\n| problem                                                                                                                                                                                 | solution                                                                                                                                                                              |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [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)                                                                                                                   |\n| [House Robber](https://leetcode.com/problems/house-robber/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/house-robber.rb)                                                                                                                   |\n| [Decode Ways](https://leetcode.com/problems/decode-ways)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/decode_ways.rb)                                                                                                                   |\n| [Coin change](https://leetcode.com/problems/coin-change/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/coin-change.rb)                                                                                                                   |\n| [Decode Strings](https://leetcode.com/problems/decode-string/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/decode_string.rb)                                                                                                                   |\n| [Wiggle Subsequence](https://leetcode.com/problems/wiggle-subsequence/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/wiggle_subsequence.rb)                                                                                                                   |\n| [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)                                                                                                                   |\n| [Unix path](https://leetcode.com/problems/simplify-path/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/simplify_path.rb)                                                                                                                   |\n| [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)                                                                                                                   |\n| [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)                                                                                                                   |\n| [Sum 4 arrays](https://leetcode.com/problems/4sum-ii/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/4-sum.rb)                                                                                                                   |\n| [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/reverse-linked-list.rb)                                                                                                                   |\n| [Reverse String In-place](https://leetcode.com/problems/reverse-string/description/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/reverse-string-inplace.rb)                                                                                                                   |\n| [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)                                                                                                                   |\n| [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/mirror.rb)                                                                                                                   |\n| [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)                                                                                                                 |\n| [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)                                                                                                                  |\n| [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)                                                                                                                  |\n| [Add two binary numbers](https://leetcode.com/problems/add-binary/description/)                                                                                                     | [click](https://github.com/sagivo/algorithms/blob/master/src/add_binary.rb)                                                                                                                  |\n| [Binary search](https://en.wikipedia.org/wiki/Binary_search_algorithm)                                                                                                                  | [click](https://github.com/sagivo/algorithms/blob/master/src/binary_search.rb)                                                                                                            |\n| [Longest increasing subsequence](http://en.wikipedia.org/wiki/Longest_increasing_subsequence)                                                                                           | [click](https://github.com/sagivo/algorithms/blob/master/src/longest_increasing_subsequence.rb)                                                                                           |\n| [Find all permutations of array](https://en.wikipedia.org/wiki/Permutation)                                                                                                             | [click](https://github.com/sagivo/algorithms/blob/master/src/permutations.rb)                                                                                                             |\n| [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)                                                                                                    |\n| [Finding the powerset of a set](http://en.wikipedia.org/wiki/Power_set)                                                                                                                 | [click](https://github.com/sagivo/algorithms/blob/master/src/powerset.rb)                                                                                                                 |\n| [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)                                                                                                             |\n| Print all combinations of set joining                                                                                                                                                   | [click](https://github.com/sagivo/algorithms/blob/master/src/join_sets.rb)                                                                                                                |\n| [count and say](https://leetcode.com/problems/count-and-say/)                                                                                                                                                   | [click](https://github.com/sagivo/algorithms/blob/master/src/count_and_say.rb)                                                                                                                |\n| [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)                                                                                                                    |\n| [Maximum contiguous subarray](https://leetcode.com/problems/maximum-subarray)                                                                                 | [click](https://github.com/sagivo/algorithms/blob/master/src/max_subarray.rb)                                                                                                                    |\n| [Max Stack](https://leetcode.com/problems/max-stack/submissions/)                                                                                 | [click](https://github.com/sagivo/algorithms/blob/master/src/max_stack.rb)                                                                                                                    |\n| [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)                                                                                              |\n| [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)                                                                                            |\n| [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)                                                                                                                      |\n| [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)                                                                                                     |\n| [Quicksort algorithm](http://en.wikipedia.org/wiki/Quicksort)                                                                                                                           | [click](https://github.com/sagivo/algorithms/blob/master/src/quicksort.rb)                                                                                                                |\n| [Mergesort algorithm](https://en.wikipedia.org/wiki/Merge_sort)                                                                                                                         | [click](https://github.com/sagivo/algorithms/blob/master/src/merge_sort.rb)                                                                                                               |\n| [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)                                                                                                               |\n| [Countingsort algorithm](http://en.wikipedia.org/wiki/Counting_sort)                                                                                                                    | [click](https://github.com/sagivo/algorithms/blob/master/src/counting_sort.rb)                                                                                                            |\n| [Shellsort algorithm](http://en.wikipedia.org/wiki/Shellsort)                                                                                                                           | [click](https://github.com/sagivo/algorithms/blob/master/src/shell_sort.rb)                                                                                                               |\n| [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)                                                                                                                 |\n| [Move Zeroes](https://leetcode.com/problems/move-zeroes)                                                                                                                       | [click](https://github.com/sagivo/algorithms/blob/master/src/move_zeroes.rb)                                                                                                                 |\n| [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) |\n| [Monty Hall Problem](https://en.wikipedia.org/wiki/Monty_hall_problem)                                                                                                                  | [click](https://github.com/sagivo/algorithms/blob/master/src/monty_hall.rb)                                                                                                               |\n| [Eucliden and Extended Eucliden algorithm](http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm)                                                                                                                  | [click](https://github.com/sagivo/algorithms/blob/master/src/gcd.rb)                                                                                                               |\n| Suggest index of a number in an array                                                                                                                  | [click](https://github.com/sagivo/algorithms/blob/master/src/sugget_index_in_array.rb)                                                                                                               |\n| [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)                                                                                                               |\n| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort)                                                                | [click](https://github.com/sagivo/algorithms/blob/master/src/insertion_sort.rb)                                                                                                               |\n| [Towers of Hanoi using Stack](https://en.wikipedia.org/wiki/Tower_of_Hanoi) | [click](blob/master/src/towers_of_hanoi_with_stack.rb)\n| [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)                                                   |\n\n\n# How?  \nSimply run `ruby some_file.rb` to execute the algorithm. At the bottom of each file there are some test samples.  \nexample: `ruby brackets_combinations.rb` will print:  \n`[\"((()))\", \"(()())\", \"(())()\", \"()(())\", \"()()()\"]`.  \n\n# Contribute\nDid you find a bug? any way to do it better? please feel free to pull-request it :)\n","funding_links":[],"categories":["Ruby","Algorithms","Github Libraries"],"sub_categories":["Windows"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagivo%2Falgorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagivo%2Falgorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagivo%2Falgorithms/lists"}