├── .vscode └── settings.json ├── 00-welcome ├── 00-welcome-to-technical-interview-preparation │ └── README.md ├── 01-algorithmic-problem-solving │ └── README.md ├── 02-a-note-on-testing │ └── README.md └── 03-problem-solving-tips │ └── README.md ├── 01-week-1--starter-algorithms ├── 00-day-1--reverse-a-string │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── reverse_string.js │ │ └── tests │ │ │ └── reverse_string.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── reverse_string.rb │ │ └── spec │ │ │ ├── reverse_string_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── reverse_string.js │ │ └── reverse_string.rb ├── 01-day-2--find-first-duplicate │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── find_first_duplicate.js │ │ ├── package.json │ │ └── tests │ │ │ └── find_first_duplicate.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── find_first_duplicate.rb │ │ └── spec │ │ │ ├── find_first_duplicate_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── find_first_duplicate.js │ │ └── find_first_duplicate.rb ├── 02-day-3--fibonacci-series │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── fibonacci.js │ │ ├── package.json │ │ └── tests │ │ │ └── fibonacci.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── fibonacci.rb │ │ └── spec │ │ │ ├── fibonacci_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── fibonacci.js │ │ └── fibonacci.rb ├── 03-day-4--selection-sort │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── selection_sort.js │ │ └── tests │ │ │ └── selection_sort.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── selection_sort.rb │ │ └── spec │ │ │ ├── selection_sort_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── selection_sort.js │ │ └── selection_sort.rb └── 04-day-5--find-shortest-string │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── find_shortest_string.js │ ├── package.json │ └── tests │ │ └── find_shortest_string.test.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── find_shortest_string.rb │ └── spec │ │ ├── find_shortest_string_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── find_shortest_string.js │ └── find_shortest_string.rb ├── 02-week-2--recursion ├── 00-introduction-to-recursion │ └── README.md ├── 01-day-1--recursive-counting │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── recursive_count.js │ │ └── tests │ │ │ └── recursive_count.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── recursive_count.rb │ │ └── spec │ │ │ ├── recursive_count_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── recursive_count.js │ │ └── recursive_count.rb ├── 02-day-2--recursive-search │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── recursive_search.js │ │ └── tests │ │ │ └── recursive_search.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── recursive_search.rb │ │ └── spec │ │ │ ├── recursive_search_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── recursive_search.js │ │ └── recursive_search.rb ├── 03-day-3--recursive-fibonacci-series │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── fibonacci_recursive.js │ │ ├── package.json │ │ └── tests │ │ │ └── fibonacci_recursive.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── fibonacci_recursive.rb │ │ └── spec │ │ │ ├── fibonacci_recursive_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── fibonacci_recursive.js │ │ └── fibonacci_recursive.rb ├── 04-day-4--recursive-find-shortest-string │ ├── .gitignore │ ├── README.md │ ├── benchmark │ │ ├── benchmark.js │ │ └── benchmark.rb │ ├── javascript │ │ ├── find_shortest_string_recursive.js │ │ ├── package.json │ │ └── tests │ │ │ └── find_shortest_string_recursive.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── find_shortest_string_recursive.rb │ │ └── spec │ │ │ ├── find_shortest_string_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── benchmark │ │ ├── benchmark.js │ │ └── benchmark.rb │ │ ├── find_shortest_string_recursive.js │ │ └── find_shortest_string_recursive.rb └── 05-day-5--recursive-selection-sort │ ├── .gitignore │ ├── README.md │ ├── benchmark │ ├── benchmark.js │ └── benchmark.rb │ ├── javascript │ ├── package.json │ ├── selection_sort_recursive.js │ └── tests │ │ └── selection_sort_recursive.test.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── selection_sort_recursive.rb │ └── spec │ │ ├── selection_sort_recursive_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── benchmark │ ├── benchmark.js │ └── benchmark.rb │ ├── selection_sort_recursive.js │ └── selection_sort_recursive.rb ├── 03-week-3--additional-practice ├── 00-bonus-1--balancing-parenetheses │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── balancing_parentheses.js │ │ ├── package.json │ │ └── tests │ │ │ └── balancing_parentheses.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── balancing_parentheses.rb │ │ └── spec │ │ │ ├── balancing_parentheses_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── balancing_parentheses.js │ │ └── balancing_parentheses.rb ├── 01-bonus-2--roman-numeral-to-integer │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── roman_numeral.js │ │ └── tests │ │ │ └── roman_numeral.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── roman_numeral.rb │ │ └── spec │ │ │ ├── roman_numeral_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── roman_numeral.js │ │ └── roman_numeral.rb ├── 02-bonus-3--rotate-array-clockwise │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── rotate_array.js │ │ └── tests │ │ │ └── rotate_array.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── rotate_array.rb │ │ └── spec │ │ │ ├── rotate_array_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── rotate_array.js │ │ └── rotate_array.rb ├── 03-bonus-4--distinct-pair-sum │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── distinct_pair_sum.js │ │ ├── package.json │ │ └── tests │ │ │ └── distinct_pair_sum.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── distinct_pair_sum.rb │ │ └── spec │ │ │ ├── distinct_pair_sum_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── distinct_pair_sum.js │ │ └── distinct_pair_sum.rb └── 04-bonus-5--consecutive-substrings │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── consecutive_substrings.js │ ├── package.json │ └── tests │ │ └── consecutive_substrings.test.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── consecutive_substrings.rb │ └── spec │ │ ├── consecutive_substrings_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── consecutive_substrings.js │ └── consecutive_substrings.rb ├── 04-pairing-exercises-1 ├── 00-code-review │ └── README.md └── 01-whiteboard │ └── README.md ├── 05-week-4--big-o-notation ├── 00-day-1--introduction-to-big-o-notation │ ├── Big-O-graph.png │ └── README.md └── 01-day-2--introduction-to-space-complexity │ └── README.md ├── 06-week-5--big-o-continued ├── 00-days-1-to-2--implement-a-stack-class │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── stack.js │ │ └── tests │ │ │ └── stack.test.js │ ├── pancakes.png │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── spec │ │ │ ├── spec_helper.rb │ │ │ └── stack_spec.rb │ │ └── stack.rb │ └── solutions │ │ ├── stack.js │ │ └── stack.rb ├── 01-days-3-to-4--implement-a-queue-class │ ├── .gitignore │ ├── README.md │ ├── grocery_store.jpg │ ├── javascript │ │ ├── package.json │ │ ├── queue.js │ │ └── tests │ │ │ └── queue.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── queue.rb │ │ └── spec │ │ │ ├── queue_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── queue.js │ │ └── queue.rb └── 02-day-5--implement-a-set │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── my_set.js │ ├── package.json │ └── tests │ │ └── my_set.test.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── my_set.rb │ └── spec │ │ ├── my_set_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── my_set.js │ └── my_set.rb ├── 07-week-6--foundational-data-structures ├── 00-days-1-to-2--implement-a-linked-list │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── linked_list.js │ │ ├── package.json │ │ └── tests │ │ │ └── linked_list.test.js │ ├── linked_list.png │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── linked_list.rb │ │ └── spec │ │ │ ├── linked_list_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── linked_list.js │ │ └── linked_list.rb ├── 01-day-3--underneath-arrays │ └── README.md ├── 02-day-4--underneath-hashes │ └── README.md ├── 03-bonus-algorithm--recursive-string-reverse │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── reverse_string.js │ │ └── tests │ │ │ └── reverse_string.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── reverse_string.rb │ │ └── spec │ │ │ ├── reverse_string_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── reverse_string.js │ │ └── reverse_string.rb ├── 04-bonus--modify-linked-list-to-track-tail-and-size │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── linked_list.js │ │ ├── package.json │ │ └── tests │ │ │ └── linked_list.test.js │ ├── linked_list.png │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── linked_list.rb │ │ └── spec │ │ │ ├── linked_list_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── linked_list.js │ │ └── linked_list.rb └── 05-bonus--build-a-doubly-linked-list │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── doubly_linked_list.js │ ├── package.json │ └── tests │ │ └── doubly_linked_list.test.js │ ├── linked_list.png │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── doubly_linked_list.rb │ └── spec │ │ ├── doubly_linked_list_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── doubly_linked_list.js │ └── doubly_linked_list.rb ├── 08-pairing-exercise-2 └── 00-whiteboard-big-o │ └── README.md ├── 09-week-7--sorting-algorithms ├── 00-days-1-to-2--bubble-sort │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── bubble_sort.js │ │ ├── package.json │ │ └── tests │ │ │ └── bubble_sort.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── bubble_sort.rb │ │ └── spec │ │ │ ├── bubble_sort_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── bubble_sort.js │ │ └── bubble_sort.rb └── 01-days-3-to-5--merge-sort │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── merge_sort.js │ ├── package.json │ └── tests │ │ └── merge_sort.test.js │ ├── merge_sort.gif │ ├── merge_sort.png │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── merge_sort.rb │ └── spec │ │ ├── merge_sort_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── merge_sort.js │ └── merge_sort.rb ├── 10-week-8--searching ├── 00-days-1-to-3--binary-search │ ├── .gitignore │ ├── README.md │ ├── binary_search.gif │ ├── javascript │ │ ├── binary_search.js │ │ ├── package.json │ │ └── tests │ │ │ └── binary_search.test.js │ ├── phone_book.jpeg │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── binary_search.rb │ │ └── spec │ │ │ ├── binary_search_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── binary_search.js │ │ └── binary_search.rb ├── 01-day-4--manual-binary-tree │ ├── .gitignore │ ├── README.md │ ├── invalid_trees.png │ ├── javascript │ │ ├── binary_tree.js │ │ ├── package.json │ │ └── tests │ │ │ └── binary_tree.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── binary_tree.rb │ │ └── spec │ │ │ ├── binary_tree_spec.rb │ │ │ └── spec_helper.rb │ ├── solutions │ │ ├── binary_tree.js │ │ └── binary_tree.rb │ ├── valid_tree.png │ └── valid_trees.png └── 02-day-5--build-a-binary-tree---balancing │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── balancing.js │ ├── package.json │ └── tests │ │ ├── balancing.test.js │ │ └── validation_methods.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── balancing.rb │ └── spec │ │ ├── balancing_spec.rb │ │ ├── spec_helper.rb │ │ └── validation_methods.rb │ ├── solutions │ ├── balancing.js │ └── balancing.rb │ ├── tree_compare.png │ ├── tree_height.png │ └── valid_trees.png ├── 11-pairing-exercise-3 └── 00-pair-programming │ └── README.md ├── 12-week-9--searching-and-sorting-continued ├── 00-days-1-to-2--binary-tree-traversal--level-order---breadth-first │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── tests │ │ │ └── tree_traversal_bfs.test.js │ │ └── tree_traversal_bfs.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── spec │ │ │ ├── spec_helper.rb │ │ │ └── tree_traversal_bfs_spec.rb │ │ └── tree_traversal_bfs.rb │ ├── solutions │ │ ├── tree_traversal_bfs.js │ │ └── tree_traversal_bfs.rb │ ├── trees.png │ └── unordered_tree.png ├── 01-day-3-to-4--tree-traversal-in-order │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── tests │ │ │ └── tree_traversal_inorder.test.js │ │ └── tree_traversal_inorder.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── spec │ │ │ ├── spec_helper.rb │ │ │ └── tree_traversal_inorder_spec.rb │ │ └── tree_traversal_inorder.rb │ ├── solutions │ │ ├── tree_traversal_inorder.js │ │ └── tree_traversal_inorder.rb │ └── trees.png ├── 02-day-5--find-value-binary-tree │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── find_target.js │ │ ├── package.json │ │ └── tests │ │ │ └── find_target.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── find_target.rb │ │ └── spec │ │ │ ├── find_target_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── find_target.js │ │ └── find_target.rb └── 03-bonus--quicksort │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── package.json │ ├── quicksort.js │ └── tests │ │ └── quicksort.test.js │ ├── quick_sort_partition_animation.gif │ ├── quicksort_diagram.png │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── quicksort.rb │ └── spec │ │ ├── quicksort_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── bonus.js │ ├── bonus.rb │ ├── quicksort.js │ └── quicksort.rb ├── 13-week-10 ├── 00-days-1-to-2--create-a-queue-class-using-nodes │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── package.json │ │ ├── queue.js │ │ └── tests │ │ │ └── queue.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── queue.rb │ │ └── spec │ │ │ ├── queue_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── queue.js │ │ └── queue.rb └── 01-days-3-to-5--build-an-lru-cache │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── lru_cache.js │ ├── package.json │ └── tests │ │ └── lru_cache.test.js │ ├── lru_cache.svg │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── lru_cache.rb │ └── spec │ │ ├── lru_cache_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── lru_cache.js │ └── lru_cache.rb ├── 14-week-11 ├── 00-day-1--what-is-a-graph- │ ├── .gitignore │ ├── README.md │ ├── friends.jpg │ ├── javascript │ │ ├── graph.js │ │ ├── package.json │ │ └── tests │ │ │ └── graph.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── graph.rb │ │ └── spec │ │ │ ├── graph_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── graph.js │ │ └── graph.rb ├── 01-days-2-to-3--depth-first-graph-traversal │ ├── .gitignore │ ├── README.md │ ├── fork_road.jpg │ ├── graph.jpg │ ├── javascript │ │ ├── graph_dfs.js │ │ ├── package.json │ │ └── tests │ │ │ └── graph_dfs.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── graph_dfs.rb │ │ └── spec │ │ │ ├── graph_dfs_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── graph_dfs.js │ │ └── graph_dfs.rb └── 02-days-4-to-5--breadth-first-graph-traversal │ ├── .gitignore │ ├── README.md │ ├── graph.jpg │ ├── javascript │ ├── find_distance.js │ ├── package.json │ └── tests │ │ └── find_distance.test.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── find_distance.rb │ └── spec │ │ ├── find_distance_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── find_distance.js │ └── find_distance.rb ├── 15-week-12 └── 00-days-1-to-2--convert-html-to-a-graph │ ├── .gitignore │ ├── README.md │ ├── javascript │ ├── package.json │ ├── table_to_graph.js │ └── tests │ │ └── table_to_graph.test.js │ ├── ruby │ ├── Gemfile │ ├── spec │ │ └── table_to_graph_spec.rb │ └── table_to_graph.rb │ └── solutions │ ├── table_to_graph.js │ └── table_to_graph.rb ├── 16-pairing-exercise-4 └── 00-whiteboard-and-calculate-big-o │ └── README.md ├── 17-week-13 ├── 00-day-1-to-2--dynamic-programming │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── fibonacci.js │ │ ├── package.json │ │ └── tests │ │ │ └── fibonacci.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── fibonacci.rb │ │ └── spec │ │ │ ├── fibonacci_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── fibonacci.js │ │ └── fibonacci.rb └── 01-day-3-to-5--add-two-numbers-list-nodes │ ├── .gitignore │ ├── README.md │ ├── example.png │ ├── javascript │ ├── addTwoList.js │ ├── package.json │ └── tests │ │ └── addTwoList.test.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── addTwoList.rb │ └── spec │ │ ├── addTwoList_spec.rb │ │ └── spec_helper.rb │ └── solutions │ ├── addTwoList.js │ └── addTwoList.rb ├── 18-week-14 ├── 00-day-1-to-2--longest-substring-without-repeating-characters │ ├── .gitignore │ ├── README.md │ ├── javascript │ │ ├── longSubString.js │ │ ├── package.json │ │ └── tests │ │ │ └── longSubString.test.js │ ├── ruby │ │ ├── .rspec │ │ ├── Gemfile │ │ ├── longSubString.rb │ │ └── spec │ │ │ ├── longSubString_spec.rb │ │ │ └── spec_helper.rb │ └── solutions │ │ ├── longSubString.js │ │ └── longSubString.rb └── 01-day-3-to-5--validate-bst │ ├── .gitignore │ ├── README.md │ ├── example-1.png │ ├── example-2.png │ ├── javascript │ ├── package.json │ ├── tests │ │ └── validBTS.test.js │ └── validBTS.js │ ├── ruby │ ├── .rspec │ ├── Gemfile │ ├── spec │ │ ├── spec_helper.rb │ │ └── valdiBTS_spec.rb │ └── validBTS.rb │ └── solutions │ ├── validBTS.js │ └── validBTS.rb ├── 19-week-15 └── 00-week-15-algo-practices │ └── README.md ├── 20-pairing-exercises-5 ├── 00-code-comparison │ └── README.md └── 01-whiteboard-and-calculate-big-o │ └── README.md └── README.md /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": ["pseudocode", "Pseudocode"] 3 | } 4 | -------------------------------------------------------------------------------- /00-welcome/02-a-note-on-testing/README.md: -------------------------------------------------------------------------------- 1 | # A Note on Testing 2 | 3 | If we have made a test suite available for a problem, please refrain from 4 | looking at or running those tests until you have: 5 | 6 | - Passed the tests given in the README 7 | - Passed the tests you wrote yourself 8 | 9 | This will give you a chance to think through the problem and write your own test 10 | cases, which is a skill you’ll need when interviewing. 11 | 12 | After you run our tests, you might notice that you missed some test cases: this 13 | is a good thing - it’s a chance for you to learn and grow as a programmer. You 14 | won’t always think of all of the necessary test cases, but as time goes by, 15 | you’ll get better and better at thinking of all of the possible inputs that need 16 | to be solved for before a solution can be considered complete. 17 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/README.md: -------------------------------------------------------------------------------- 1 | # Day 1: Reverse a String 2 | 3 | For this task, you'll need to reverse a string. Your method will receive one 4 | argument, a string, and be expected to output that string with its letters in 5 | reverse order. 6 | 7 | ```js 8 | Input: "hi" 9 | Output: "ih" 10 | 11 | Input: "catbaby" 12 | Output: "ybabtac" 13 | ``` 14 | 15 | **Do not call any type of built-in reverse method!** 16 | 17 | Please solve the problem using iteration. 18 | 19 | Use the language of your choosing. We've included starter files for some 20 | languages where you can pseudocode, explain your solution and code. 21 | 22 | ## Before you start coding 23 | 24 | 1. Rewrite the problem in your own words 25 | 2. Validate that you understand the problem 26 | 3. Write your own test cases 27 | 4. Pseudocode 28 | 5. Code! 29 | 30 | **_And remember, don't run our tests until you've passed your own!_** 31 | 32 | ## How to run your own tests 33 | 34 | ### Ruby 35 | 36 | 1. `cd` into the ruby folder 37 | 2. `ruby .rb` 38 | 39 | ### JavaScript 40 | 41 | 1. `cd` into the javascript folder 42 | 2. `node .js` 43 | 44 | ## How to run our tests 45 | 46 | ### Ruby 47 | 48 | 1. `cd` into the ruby folder 49 | 2. `bundle install` 50 | 3. `rspec` 51 | 52 | ### JavaScript 53 | 54 | 1. `cd` into the javascript folder 55 | 2. `npm i` 56 | 3. `npm test` 57 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reverse_string", 3 | "version": "1.0.0", 4 | "description": "reverse a string", 5 | "main": "reverse_string.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/javascript/reverse_string.js: -------------------------------------------------------------------------------- 1 | function reverseString(str) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 'ih'"); 8 | console.log("=>", reverseString("hi")); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 'ybabtac'"); 13 | console.log("=>", reverseString("catbaby")); 14 | } 15 | 16 | module.exports = reverseString; 17 | 18 | // Please add your pseudocode to this file 19 | // And a written explanation of your solution 20 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/javascript/tests/reverse_string.test.js: -------------------------------------------------------------------------------- 1 | const reverseString = require('../reverse_string'); 2 | 3 | test("can handle an empty string", () => { 4 | expect(reverseString("")).toBe(""); 5 | }); 6 | 7 | test("can handle a single character", () => { 8 | expect(reverseString("a")).toBe("a"); 9 | }); 10 | 11 | test("can handle two characters", () => { 12 | expect(reverseString("ab")).toBe("ba"); 13 | }); 14 | 15 | test("can handle three characters", () => { 16 | expect(reverseString("cat")).toBe("tac"); 17 | }); 18 | 19 | test("can handle many characters", () => { 20 | expect(reverseString("sham-meow")).toBe("sham-meow".split("").reverse().join("")); 21 | }); 22 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/ruby/reverse_string.rb: -------------------------------------------------------------------------------- 1 | def reverse_string(str) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 'ih'" 7 | puts "=>", reverse_string('hi') 8 | 9 | puts 10 | 11 | puts "Expecting: 'ybabtac'" 12 | puts "=>", reverse_string('catbaby') 13 | 14 | # Don't forget to add your own! 15 | end 16 | 17 | # Please add your pseudocode to this file 18 | # And a written explanation of your solution -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/00-day-1--reverse-a-string/ruby/spec/reverse_string_spec.rb: -------------------------------------------------------------------------------- 1 | require './reverse_string' 2 | 3 | RSpec.describe '#reverse_string' do 4 | it "can handle an empty string" do 5 | expect(reverse_string('')).to eq('') 6 | end 7 | 8 | it "can handle a single character" do 9 | expect(reverse_string('a')).to eq('a') 10 | end 11 | 12 | it "can handle two characters" do 13 | expect(reverse_string('ab')).to eq('ba') 14 | end 15 | 16 | it "can handle three characters" do 17 | expect(reverse_string('cat')).to eq('tac') 18 | end 19 | 20 | it "can handle many characters" do 21 | expect(reverse_string('sham-meow')).to eq('sham-meow'.reverse) 22 | end 23 | end -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/README.md: -------------------------------------------------------------------------------- 1 | # Day 2: Find First Duplicate 2 | 3 | Given an Array, find the first duplicate value that occurs. If there are no 4 | duplicates, return -1. 5 | 6 | ```js 7 | Input: [2, 1, 3, 3, 2] 8 | Output: 3 9 | 10 | Input: [1, 2, 3, 4] 11 | Output: -1 12 | ``` 13 | 14 | Use the language of your choosing. We've included starter files for some 15 | languages where you can pseudocode, explain your solution and code. 16 | 17 | ## Before you start coding: 18 | 19 | 1. Rewrite the problem in your own words 20 | 2. Validate that you understand the problem 21 | 3. Write your own test cases 22 | 4. Pseudocode 23 | 5. Code! 24 | 25 | **_And remember, don't run our tests until you've passed your own!_** 26 | 27 | ## How to run your own tests 28 | 29 | ### Ruby 30 | 31 | 1. `cd` into the ruby folder 32 | 2. `ruby .rb` 33 | 34 | ### JavaScript 35 | 36 | 1. `cd` into the javascript folder 37 | 2. `node .js` 38 | 39 | ## How to run our tests 40 | 41 | ### Ruby 42 | 43 | 1. `cd` into the ruby folder 44 | 2. `bundle install` 45 | 3. `rspec` 46 | 47 | ### JavaScript 48 | 49 | 1. `cd` into the javascript folder 50 | 2. `npm i` 51 | 3. `npm test` 52 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/javascript/find_first_duplicate.js: -------------------------------------------------------------------------------- 1 | function findFirstDuplicate(arr) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 3"); 8 | console.log("=>", findFirstDuplicate([2, 1, 3, 3, 2])); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: -1"); 13 | console.log("=>", findFirstDuplicate([1, 2, 3, 4])); 14 | } 15 | 16 | module.exports = findFirstDuplicate; 17 | 18 | // Please add your pseudocode to this file 19 | // And a written explanation of your solution 20 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "find_first_duplicate", 3 | "version": "1.0.0", 4 | "description": "find_first_duplicate", 5 | "main": "find_first_duplicate.js", 6 | "dependencies": {}, 7 | "devDependencies": { 8 | "jest": "^26.6.3" 9 | }, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/javascript/tests/find_first_duplicate.test.js: -------------------------------------------------------------------------------- 1 | const findFirstDuplicate = require('../find_first_duplicate'); 2 | 3 | test('can handle an empty array', () => { 4 | expect(findFirstDuplicate([])).toBe(-1); 5 | }); 6 | 7 | test('can handle an array containing one element', () => { 8 | expect(findFirstDuplicate([4])).toBe(-1); 9 | }); 10 | 11 | test('finds the first duplicate when there is only one duplicate', () => { 12 | expect(findFirstDuplicate([2, 2])).toBe(2); 13 | }); 14 | 15 | test('finds the first duplicate in an Array containing multiple duplicates', () => { 16 | expect(findFirstDuplicate([1, 2, 3, 3, 2, 1])).toBe(3); 17 | }); 18 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/ruby/find_first_duplicate.rb: -------------------------------------------------------------------------------- 1 | def find_first_duplicate(arr) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 3" 7 | puts "=>", find_first_duplicate([2, 1, 3, 3, 2]) 8 | 9 | puts 10 | 11 | puts "Expecting: -1" 12 | puts "=>", find_first_duplicate([1, 2, 3, 4]) 13 | 14 | # Don't forget to add your own! 15 | end 16 | 17 | # Please add your pseudocode to this file 18 | # And a written explanation of your solution 19 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/01-day-2--find-first-duplicate/ruby/spec/find_first_duplicate_spec.rb: -------------------------------------------------------------------------------- 1 | require './find_first_duplicate' 2 | 3 | RSpec.describe '#find_first_duplicate' do 4 | it 'can handle an empty array' do 5 | expect(find_first_duplicate([])).to eq(-1) 6 | end 7 | 8 | it 'can handle an array containing one element' do 9 | expect(find_first_duplicate([4])).to eq(-1) 10 | end 11 | 12 | it 'finds the first duplicate when there is only one duplicate' do 13 | expect(find_first_duplicate([2, 2])).to eq(2) 14 | end 15 | 16 | it 'finds the first duplicate in an Array containing multiple duplicates' do 17 | expect(find_first_duplicate([1, 2, 3, 3, 2, 1])).to eq(3) 18 | end 19 | end -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/README.md: -------------------------------------------------------------------------------- 1 | # Day 3: Fibonacci Series 2 | 3 | Find the nth element in the Fibonacci series. The Fibonacci sequence starts with 4 | a 0 followed by a 1. After that, every value is the sum of the two values 5 | preceding it. Here are the first seven values as an example: 0, 1, 1, 2, 3, 5, 6 | 8. 7 | 8 | ``` 9 | Input: 0 10 | Output: 0 11 | 12 | Input: 2 13 | Output: 1 14 | 15 | Input: 10 16 | Output: 55 17 | ``` 18 | 19 | Note that we are using zero-indexing for the series. 20 | 21 | Use the language of your choosing. We've included starter files for some 22 | languages where you can pseudocode, explain your solution and code. 23 | 24 | ## Before you start coding: 25 | 26 | 1. Rewrite the problem in your own words 27 | 2. Validate that you understand the problem 28 | 3. Write your own test cases 29 | 4. Pseudocode 30 | 5. Code! 31 | 32 | **_And remember, don't run our tests until you've passed your own!_** 33 | 34 | ## How to run your own tests 35 | 36 | ### Ruby 37 | 38 | 1. `cd` into the ruby folder 39 | 2. `ruby .rb` 40 | 41 | ### JavaScript 42 | 43 | 1. `cd` into the javascript folder 44 | 2. `node .js` 45 | 46 | ## How to run our tests 47 | 48 | ### Ruby 49 | 50 | 1. `cd` into the ruby folder 51 | 2. `bundle install` 52 | 3. `rspec` 53 | 54 | ### JavaScript 55 | 56 | 1. `cd` into the javascript folder 57 | 2. `npm i` 58 | 3. `npm test` 59 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/javascript/fibonacci.js: -------------------------------------------------------------------------------- 1 | function fibonacci(num) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 0"); 8 | console.log("=>", fibonacci(0)); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 1"); 13 | console.log("=>", fibonacci(2)); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 55"); 18 | console.log("=>", fibonacci(10)); 19 | } 20 | 21 | module.exports = fibonacci; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fibonacci", 3 | "version": "1.0.0", 4 | "description": "find nth value in fibo sequence", 5 | "main": "fibonacci.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/javascript/tests/fibonacci.test.js: -------------------------------------------------------------------------------- 1 | const fibonacci = require('../fibonacci'); 2 | 3 | const fibo = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811]; 4 | 5 | for (let i = 0; i < 10; ++i) { 6 | test(`outputs the correct number in the sequence at index ${i}`, () => { 7 | expect(fibonacci(i)).toBe(fibo[i]); 8 | }); 9 | } 10 | 11 | test('outputs the correct number in the sequence at index 28', () => { 12 | expect(fibonacci(28)).toBe(fibo[28]); 13 | }); 14 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/ruby/fibonacci.rb: -------------------------------------------------------------------------------- 1 | def fibonacci(num) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 0" 7 | puts "=>", fibonacci(0) 8 | 9 | puts 10 | 11 | puts "Expecting: 1" 12 | puts "=>", fibonacci(2) 13 | 14 | puts 15 | 16 | puts "Expecting: 55" 17 | puts "=>", fibonacci(10) 18 | 19 | # Don't forget to add your own! 20 | end 21 | 22 | # Please add your pseudocode to this file 23 | # And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/02-day-3--fibonacci-series/ruby/spec/fibonacci_spec.rb: -------------------------------------------------------------------------------- 1 | require './fibonacci' 2 | 3 | RSpec.describe '#fibonacci' do 4 | fibo = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811] 5 | 6 | 10.times do |n| 7 | it "outputs the correct number in the sequence at index #{n}" do 8 | expect(fibonacci(n)).to eq(fibo[n]) 9 | end 10 | end 11 | 12 | it "outputs the correct number at index 28" do 13 | expect(fibonacci(28)).to eq(fibo[28]) 14 | end 15 | end -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "selection-sort", 3 | "version": "1.0.0", 4 | "description": "sort using selection sort", 5 | "main": "selection_sort.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/javascript/selection_sort.js: -------------------------------------------------------------------------------- 1 | function selectionSort(arr) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: [-1, 2, 3, 5]"); 8 | console.log("=>", selectionSort([3, -1, 5, 2])); 9 | 10 | console.log(""); 11 | 12 | // BENCHMARK HERE, and print the average runtime 13 | const longInput = []; 14 | 15 | for (let i = 0; i < 100; ++i) { 16 | longInput.push(Math.random()); 17 | } 18 | } 19 | 20 | module.exports = selectionSort; 21 | 22 | // Please add your pseudocode to this file 23 | // And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/javascript/tests/selection_sort.test.js: -------------------------------------------------------------------------------- 1 | const selectionSort = require('../selection_sort'); 2 | 3 | test('can handle an empty array', () => { 4 | expect(selectionSort([])).toEqual([]); 5 | }); 6 | 7 | test('can sort one element', () => { 8 | expect(selectionSort([5])).toEqual([5]); 9 | }); 10 | 11 | test('can sort two elements', () => { 12 | expect(selectionSort([3, 1])).toEqual([1, 3]); 13 | }); 14 | 15 | test('can sort several elements', () => { 16 | expect(selectionSort([10, 4, 3, 2, 1, 5])).toEqual([1, 2, 3, 4, 5, 10]); 17 | }); 18 | 19 | test('can sort negative and positive values', () => { 20 | expect(selectionSort([-1, -2, 4, 2])).toEqual([-2, -1, 2, 4]); 21 | }); 22 | 23 | test('can sort an array containing repeating values', () => { 24 | expect(selectionSort([1, 4, 2, 1, 2, 4, 20, -2])).toEqual([1, 4, 2, 1, 2, 4, 20, -2].sort((a, b) => a - b)); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/ruby/selection_sort.rb: -------------------------------------------------------------------------------- 1 | def selection_sort(arr) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: [-1, 2, 3, 5]" 7 | print "=> " 8 | print selection_sort([3, -1, 5, 2]) 9 | 10 | puts 11 | 12 | # Don't forget to add your own! 13 | 14 | # BENCHMARK HERE, you can print the average runtime 15 | long_input = [] 16 | 17 | 100.times { long_input << rand } 18 | end 19 | 20 | # Please add your pseudocode to this file 21 | # And a written explanation of your solution 22 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/03-day-4--selection-sort/ruby/spec/selection_sort_spec.rb: -------------------------------------------------------------------------------- 1 | require './selection_sort' 2 | 3 | RSpec.describe '#selection_sort' do 4 | it 'can handle an empty array' do 5 | expect(selection_sort([])).to eq([]) 6 | end 7 | 8 | it 'can sort one element' do 9 | expect(selection_sort([5])).to eq([5]) 10 | end 11 | 12 | it 'can sort two elements' do 13 | expect(selection_sort([3, 1])).to eq([1, 3]) 14 | end 15 | 16 | it 'can sort several elements' do 17 | expect(selection_sort([10, 4, 3, 2, 1, 5])).to eq([1, 2, 3, 4, 5, 10]) 18 | end 19 | 20 | it 'can sort negative and positive values' do 21 | expect(selection_sort([-1, -2, 4, 2])).to eq([-2, -1, 2, 4]) 22 | end 23 | 24 | it 'can sort an array containing repeating values' do 25 | expect(selection_sort([1, 4, 2, 1, 2, 4, 20, -2])).to eq([1, 4, 2, 1, 2, 4, 20, -2].sort) 26 | end 27 | end -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/javascript/find_shortest_string.js: -------------------------------------------------------------------------------- 1 | function findShortestString(arr) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 'a'"); 8 | console.log("=>", findShortestString(['aaa', 'a', 'bb', 'ccc'])); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 'hi'"); 13 | console.log("=>", findShortestString(['cat', 'hi', 'dog', 'an'])); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 'lily'"); 18 | console.log("=>", findShortestString(['flower', 'juniper', 'lily', 'dadelion'])); 19 | 20 | // BENCHMARK HERE 21 | } 22 | 23 | module.exports = findShortestString; 24 | 25 | // Please add your pseudocode to this file 26 | // And a written explanation of your solution 27 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "find_shortest_string", 3 | "version": "1.0.0", 4 | "description": "find shortest string in a list", 5 | "main": "find_shortest_string.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/javascript/tests/find_shortest_string.test.js: -------------------------------------------------------------------------------- 1 | const findShortestString = require('../find_shortest_string'); 2 | 3 | test('can handle an array containing one string', () => { 4 | expect(findShortestString(['cat'])).toBe('cat'); 5 | }); 6 | 7 | test('returns the shortest string when there is only one', () => { 8 | expect(findShortestString(['dogbaby', 'cat', 'jammy', 'hamtaro'])).toBe('cat'); 9 | }); 10 | 11 | test('returns the first occurrence of the shortest string when there are several', () => { 12 | expect(findShortestString(['stuff', 'a', 'things', 'b', 'two'])).toBe('a'); 13 | }); 14 | 15 | test('returns the empty string', () => { 16 | expect(findShortestString(['things', 'crabapple', '', 'stuff'])).toBe(''); 17 | }); 18 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/ruby/find_shortest_string.rb: -------------------------------------------------------------------------------- 1 | def find_shortest_string(arr) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 'a'" 7 | puts "=>", find_shortest_string(['aaa', 'a', 'bb', 'ccc']) 8 | 9 | puts 10 | 11 | puts "Expecting: 'hi'" 12 | puts "=>", find_shortest_string(['cat', 'hi', 'dog', 'an']) 13 | 14 | puts 15 | 16 | puts "Expecting: 'lily'" 17 | puts "=>", find_shortest_string(['flower', 'juniper', 'lily', 'dadelion']) 18 | 19 | # Don't forget to add your own! 20 | 21 | # BENCHMARK HERE 22 | end 23 | 24 | # Please add your pseudocode to this file 25 | # And a written explanation of your solution 26 | -------------------------------------------------------------------------------- /01-week-1--starter-algorithms/04-day-5--find-shortest-string/ruby/spec/find_shortest_string_spec.rb: -------------------------------------------------------------------------------- 1 | require './find_shortest_string' 2 | 3 | RSpec.describe '#find_shortest_string' do 4 | it 'can handle an array containing one string' do 5 | expect(find_shortest_string(['cat'])).to eq('cat') 6 | end 7 | 8 | it 'returns the shortest string when there is only one' do 9 | expect(find_shortest_string(['dogbaby', 'cat', 'jammy', 'hamtaro'])).to eq('cat') 10 | end 11 | 12 | it 'returns the first occurrence of the shortest string when there are several' do 13 | expect(find_shortest_string(['stuff', 'a', 'things', 'b', 'two'])).to eq('a') 14 | end 15 | 16 | it 'returns the empty string' do 17 | expect(find_shortest_string(['things', 'crabapple', '', 'stuff'])).to eq('') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recursive_count", 3 | "version": "1.0.0", 4 | "description": "recursively count", 5 | "main": "recursive_count.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/javascript/recursive_count.js: -------------------------------------------------------------------------------- 1 | function recursiveCount(num = 0) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | recursiveCount(); 7 | } 8 | 9 | module.exports = recursiveCount; 10 | 11 | // OPTIONAL 12 | // Please add your pseudocode to this file 13 | // And a written explanation of your solution 14 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/javascript/tests/recursive_count.test.js: -------------------------------------------------------------------------------- 1 | const recursiveCount = require('../recursive_count'); 2 | 3 | test('logs numbers 0 to 9', () => { 4 | console.log = jest.fn(); 5 | recursiveCount(); 6 | 7 | for (let i = 0; i < 10; ++i) { 8 | expect(console.log).toHaveBeenCalledWith(i); 9 | } 10 | }); 11 | 12 | test('returns undefined', () => { 13 | expect(recursiveCount()).toBe(undefined); 14 | }); -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/ruby/recursive_count.rb: -------------------------------------------------------------------------------- 1 | def recursive_count(num = 0) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | recursive_count 7 | end 8 | 9 | # OPTIONAL 10 | # Please add your pseudocode to this file 11 | # And a written explanation of your solution 12 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/ruby/spec/recursive_count_spec.rb: -------------------------------------------------------------------------------- 1 | require './recursive_count' 2 | 3 | RSpec.describe '#recursive_count' do 4 | it 'outputs numbers 0 to 9' do 5 | expect { recursive_count }.to output("0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n").to_stdout 6 | end 7 | 8 | it 'returns nil' do 9 | expect(recursive_count).to be_nil 10 | end 11 | end -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/solutions/recursive_count.js: -------------------------------------------------------------------------------- 1 | function recursiveCount(num = 0) { 2 | if (num >= 10) { 3 | return; 4 | } 5 | 6 | console.log(num); 7 | recursiveCount(num + 1); 8 | 9 | // THIS IS ALSO A VALID OPTION INSTEAD OF THE ABOVE 10 | // recursiveCount(++num); 11 | 12 | // THIS WILL CAUSE A STACK OVERFLOW. WHY? 13 | // recursiveCount(num++); 14 | 15 | // IF YOU LOG NUM BELOW, THE NUMBERS PRINT BACKWARDS FROM 9 TO 0. WHY? 16 | // console.log(num); 17 | } 18 | 19 | if (require.main === module) { 20 | recursiveCount(); 21 | } 22 | 23 | module.exports = recursiveCount; 24 | 25 | // OPTIONAL 26 | // Please add your pseudocode to this file 27 | // And a written explanation of your solution 28 | -------------------------------------------------------------------------------- /02-week-2--recursion/01-day-1--recursive-counting/solutions/recursive_count.rb: -------------------------------------------------------------------------------- 1 | def recursive_count(num = 0) 2 | # BASE CASE 3 | return if num >= 10 4 | 5 | puts num 6 | recursive_count(num + 1) 7 | # IF YOU PUTS NUM BELOW, THE NUMBERS PRINT BACKWARDS FROM 9 TO 0. WHY? 8 | # puts num 9 | end 10 | 11 | if __FILE__ == $PROGRAM_NAME 12 | recursive_count 13 | end 14 | 15 | # OPTIONAL 16 | # Please add your pseudocode to this file 17 | # And a written explanation of your solution 18 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "recursive_search", 3 | "version": "1.0.0", 4 | "description": "recursive search", 5 | "main": "recursive_search.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/javascript/recursive_search.js: -------------------------------------------------------------------------------- 1 | function recursiveSearch(arr, target) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: true"); 8 | console.log("=>", recursiveSearch([1, 2, 3], 2)); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: false"); 13 | console.log("=>", recursiveSearch([3, 2, 1], 4)); 14 | } 15 | 16 | module.exports = recursiveSearch; 17 | 18 | // Please add your pseudocode to this file 19 | // And a written explanation of your solution 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/javascript/tests/recursive_search.test.js: -------------------------------------------------------------------------------- 1 | const recursiveSearch = require('../recursive_search'); 2 | 3 | test('returns false when given an empty array', () => { 4 | expect(recursiveSearch([], 7)).toBe(false); 5 | }); 6 | 7 | test('returns true when the target is in the array', () => { 8 | expect(recursiveSearch([7], 7)).toBe(true); 9 | expect(recursiveSearch([1, 2, 3], 2)).toBe(true); 10 | expect(recursiveSearch([1, 2, 3], 3)).toBe(true); 11 | }); 12 | 13 | test('returns false when the target is not in the array', () => { 14 | expect(recursiveSearch([3], 7)).toBe(false); 15 | expect(recursiveSearch([1, 2, 3], 5)).toBe(false); 16 | }); 17 | 18 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/ruby/recursive_search.rb: -------------------------------------------------------------------------------- 1 | def recursive_search(arr, target) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: true" 7 | puts "=>", recursive_search([1, 2, 3], 2) 8 | 9 | puts 10 | 11 | puts "Expecting: false" 12 | puts "=>", recursive_search([3, 2, 1], 4) 13 | 14 | # Don't forget to add your own! 15 | end 16 | 17 | # Please add your pseudocode to this file 18 | # And a written explanation of your solution 19 | -------------------------------------------------------------------------------- /02-week-2--recursion/02-day-2--recursive-search/ruby/spec/recursive_search_spec.rb: -------------------------------------------------------------------------------- 1 | require './recursive_search' 2 | 3 | RSpec.describe '#recursive_search' do 4 | it 'returns false when given an empty array' do 5 | expect(recursive_search([], 7)).to be false 6 | end 7 | 8 | it 'returns true when the target is in the array' do 9 | expect(recursive_search([7], 7)).to be true 10 | expect(recursive_search([1, 2, 3], 2)).to be true 11 | expect(recursive_search([1, 2, 3], 3)).to be true 12 | end 13 | 14 | it 'returns false when the target is not in the array' do 15 | expect(recursive_search([3], 7)).to be false 16 | expect(recursive_search([1, 2, 3], 5)).to be false 17 | end 18 | end -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/javascript/fibonacci_recursive.js: -------------------------------------------------------------------------------- 1 | function fibonacci(n) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 0"); 8 | console.log("=>", fibonacci(0)); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 1"); 13 | console.log("=>", fibonacci(2)); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 55"); 18 | console.log("=>", fibonacci(10)); 19 | } 20 | 21 | module.exports = fibonacci; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fibonacci_recursive", 3 | "version": "1.0.0", 4 | "description": "recursive fibo", 5 | "main": "fibonacci_recursive.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/javascript/tests/fibonacci_recursive.test.js: -------------------------------------------------------------------------------- 1 | const fibonacci = require('../fibonacci_recursive'); 2 | 3 | const fibo = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811]; 4 | 5 | for (let i = 0; i < 10; ++i) { 6 | test(`outputs the correct number in the sequence at index ${i}`, () => { 7 | expect(fibonacci(i)).toBe(fibo[i]); 8 | }); 9 | } 10 | 11 | test('outputs the correct number in the sequence at index 28', () => { 12 | expect(fibonacci(28)).toBe(fibo[28]); 13 | }); 14 | -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/ruby/fibonacci_recursive.rb: -------------------------------------------------------------------------------- 1 | def fibonacci(n) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 0" 7 | puts "=>", fibonacci(0) 8 | 9 | puts 10 | 11 | puts "Expecting: 1" 12 | puts "=>", fibonacci(2) 13 | 14 | puts 15 | 16 | puts "Expecting: 55" 17 | puts "=>", fibonacci(10) 18 | 19 | # Don't forget to add your own! 20 | end 21 | 22 | # Please add your pseudocode to this file 23 | # And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /02-week-2--recursion/03-day-3--recursive-fibonacci-series/ruby/spec/fibonacci_recursive_spec.rb: -------------------------------------------------------------------------------- 1 | require './fibonacci_recursive' 2 | 3 | RSpec.describe '#fibonacci' do 4 | fibo = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811] 5 | 6 | 10.times do |n| 7 | it "outputs the correct number in the sequence at index #{n}" do 8 | expect(fibonacci(n)).to eq(fibo[n]) 9 | end 10 | end 11 | 12 | it "outputs the correct number at index 28" do 13 | expect(fibonacci(28)).to eq(fibo[28]) 14 | end 15 | end -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | // Paste your iterative and recursive solutions in this file 2 | // And then calculate their average run times to compare them. 3 | 4 | 5 | 6 | 7 | 8 | 9 | function benchmark(callback) { 10 | const startTime = Date.now(); 11 | 12 | for (let i = 0; i < 1000; ++i) { 13 | callback(); 14 | } 15 | 16 | return (Date.now() - startTime) / 1000; 17 | } 18 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/benchmark/benchmark.rb: -------------------------------------------------------------------------------- 1 | # Paste your iterative and recursive solutions in this file 2 | # And then calculate their average run times to compare them. 3 | 4 | 5 | 6 | def benchmark 7 | start_time = Time.now 8 | 9 | 1000.times do 10 | yield 11 | end 12 | 13 | (Time.now - start_time) / 1000 14 | end 15 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/javascript/find_shortest_string_recursive.js: -------------------------------------------------------------------------------- 1 | function findShortestStringRecursive(arr) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 'a'"); 8 | console.log("=>", findShortestStringRecursive(['aaa', 'a', 'bb', 'ccc'])); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 'hi'"); 13 | console.log("=>", findShortestStringRecursive(['cat', 'hi', 'dog', 'an'])); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 'lily'"); 18 | console.log("=>", findShortestStringRecursive(['flower', 'juniper', 'lily', 'dandelion'])); 19 | } 20 | 21 | module.exports = findShortestStringRecursive; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "find_shortest_string_recursive", 3 | "version": "1.0.0", 4 | "description": "find_shortest_string_recursive", 5 | "main": "find_shortest_string_recursive.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/javascript/tests/find_shortest_string_recursive.test.js: -------------------------------------------------------------------------------- 1 | const findShortestStringRecursive = require('../find_shortest_string_recursive'); 2 | 3 | test('can handle an array containing one string', () => { 4 | expect(findShortestStringRecursive(['cat'])).toBe('cat'); 5 | }); 6 | 7 | test('returns the shortest string when there is only one', () => { 8 | expect(findShortestStringRecursive(['dogbaby', 'cat', 'jammy', 'hamtaro'])).toBe('cat'); 9 | }); 10 | 11 | test('returns the first occurrence of the shortest string when there are several', () => { 12 | expect(findShortestStringRecursive(['stuff', 'a', 'things', 'b', 'two'])).toBe('a'); 13 | }); 14 | 15 | test('returns the empty string', () => { 16 | expect(findShortestStringRecursive(['things', 'crabapple', '', 'stuff'])).toBe(''); 17 | }); 18 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/ruby/find_shortest_string_recursive.rb: -------------------------------------------------------------------------------- 1 | def find_shortest_string_recursive(arr) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 'a'" 7 | puts "=>", find_shortest_string_recursive(['aaa', 'a', 'bb', 'ccc']) 8 | 9 | puts 10 | 11 | puts "Expecting: 'hi'" 12 | puts "=>", find_shortest_string_recursive(['cat', 'hi', 'dog', 'an']) 13 | 14 | puts 15 | 16 | puts "Expecting: 'lily'" 17 | puts "=>", find_shortest_string_recursive(['flower', 'juniper', 'lily', 'dandelion']) 18 | 19 | # Don't forget to add your own! 20 | end 21 | 22 | # Please add your pseudocode to this file 23 | # And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/ruby/spec/find_shortest_string_spec.rb: -------------------------------------------------------------------------------- 1 | require './find_shortest_string_recursive' 2 | 3 | RSpec.describe '#find_shortest_string' do 4 | it 'can handle an array containing one string' do 5 | expect(find_shortest_string_recursive(['cat'])).to eq('cat') 6 | end 7 | 8 | it 'returns the shortest string when there is only one' do 9 | expect(find_shortest_string_recursive(['dogbaby', 'cat', 'jammy', 'hamtaro'])).to eq('cat') 10 | end 11 | 12 | it 'returns the first occurrence of the shortest string when there are several' do 13 | expect(find_shortest_string_recursive(['stuff', 'a', 'things', 'b', 'two'])).to eq('a') 14 | end 15 | 16 | it 'returns the empty string' do 17 | expect(find_shortest_string_recursive(['things', 'crabapple', '', 'stuff'])).to eq('') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/solutions/benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | function findShortestString(arr) { 2 | return arr.reduce((shortest, string) => 3 | string.length < shortest.length ? string : shortest 4 | ); 5 | } 6 | 7 | function findShortestStringRecursive(arr) { 8 | if (arr.length === 1) { 9 | return arr[0]; 10 | } 11 | 12 | const result = findShortestStringRecursive(arr.slice(1)); 13 | 14 | return arr[0].length <= result.length ? arr[0] : result; 15 | } 16 | 17 | function benchmark(callback) { 18 | const startTime = Date.now(); 19 | 20 | for (let i = 0; i < 1000; ++i) { 21 | callback(); 22 | } 23 | 24 | return (Date.now() - startTime) / 1000; 25 | } 26 | 27 | console.log('Iterative:', benchmark(() => findShortestString(['cat', 'dogs', '', 'bats', 'flags']))); 28 | console.log('Recursive:', benchmark(() => findShortestStringRecursive(['cat', 'dogs', '', 'bats', 'flags']))); -------------------------------------------------------------------------------- /02-week-2--recursion/04-day-4--recursive-find-shortest-string/solutions/benchmark/benchmark.rb: -------------------------------------------------------------------------------- 1 | def find_shortest_string(arr) 2 | arr.reduce do |shortest, string| 3 | string.length < shortest.length ? string : shortest 4 | end 5 | end 6 | 7 | def find_shortest_string_recursive(arr) 8 | return arr.first if arr.length == 1 9 | 10 | result = find_shortest_string_recursive(arr[1..-1]) 11 | 12 | arr.first.length <= result.length ? arr.first : result 13 | end 14 | 15 | def benchmark 16 | start_time = Time.now 17 | 18 | 1000.times do 19 | yield 20 | end 21 | 22 | (Time.now - start_time) / 1000 23 | end 24 | 25 | puts "Iterative: #{benchmark { find_shortest_string(['cat', 'dogs', '', 'bats', 'flags']) }}" 26 | puts "Recursive: #{benchmark { find_shortest_string_recursive(['cat', 'dogs', '', 'bats', 'flags']) }}" 27 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | // Paste your iterative and recursive solutions in this file 2 | // And then calculate their average run times to compare them. 3 | 4 | 5 | 6 | 7 | 8 | 9 | function benchmark(callback) { 10 | const startTime = Date.now(); 11 | 12 | for (let i = 0; i < 1000; ++i) { 13 | callback(); 14 | } 15 | 16 | return (Date.now() - startTime) / 1000; 17 | } 18 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/benchmark/benchmark.rb: -------------------------------------------------------------------------------- 1 | # Paste your iterative and recursive solutions in this file 2 | # And then calculate their average run times to compare them. 3 | 4 | 5 | 6 | def benchmark 7 | start_time = Time.now 8 | 9 | 1000.times do 10 | yield 11 | end 12 | 13 | (Time.now - start_time) / 1000 14 | end 15 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "selection_sort_recursive", 3 | "version": "1.0.0", 4 | "description": "selection_sort_recursive", 5 | "main": "selection_sort_recursive.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/javascript/selection_sort_recursive.js: -------------------------------------------------------------------------------- 1 | function selectionSortRecursive(arr) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: [-1, 2, 3, 5]"); 8 | console.log("=>", selectionSortRecursive([3, -1, 5, 2])); 9 | 10 | console.log(""); 11 | } 12 | 13 | module.exports = selectionSortRecursive; 14 | 15 | // Please add your pseudocode to this file 16 | // And a written explanation of your solution 17 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/javascript/tests/selection_sort_recursive.test.js: -------------------------------------------------------------------------------- 1 | const selectionSortRecursive = require('../selection_sort_recursive'); 2 | 3 | test('can handle an empty array', () => { 4 | expect(selectionSortRecursive([])).toEqual([]); 5 | }); 6 | 7 | test('can sort one element', () => { 8 | expect(selectionSortRecursive([5])).toEqual([5]); 9 | }); 10 | 11 | test('can sort two elements', () => { 12 | expect(selectionSortRecursive([3, 1])).toEqual([1, 3]); 13 | }); 14 | 15 | test('can sort several elements', () => { 16 | expect(selectionSortRecursive([10, 4, 3, 2, 1, 5])).toEqual([1, 2, 3, 4, 5, 10]); 17 | }); 18 | 19 | test('can sort negative and positive values', () => { 20 | expect(selectionSortRecursive([-1, -2, 4, 2])).toEqual([-2, -1, 2, 4]); 21 | }); 22 | 23 | test('can sort an array containing repeating values', () => { 24 | expect(selectionSortRecursive([1, 4, 2, 1, 2, 4, 20, -2])).toEqual([1, 4, 2, 1, 2, 4, 20, -2].sort((a, b) => a - b)); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/ruby/selection_sort_recursive.rb: -------------------------------------------------------------------------------- 1 | def selection_sort_recursive(arr) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: [-1, 2, 3, 5]" 7 | print "=> " 8 | print selection_sort_recursive([3, -1, 5, 2]) 9 | 10 | puts 11 | 12 | # Don't forget to add your own! 13 | end 14 | 15 | # Please add your pseudocode to this file 16 | # And a written explanation of your solution 17 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/ruby/spec/selection_sort_recursive_spec.rb: -------------------------------------------------------------------------------- 1 | require './selection_sort_recursive' 2 | 3 | RSpec.describe '#selection_sort_recursive' do 4 | it 'can handle an empty array' do 5 | expect(selection_sort_recursive([])).to eq([]) 6 | end 7 | 8 | it 'can sort one element' do 9 | expect(selection_sort_recursive([5])).to eq([5]) 10 | end 11 | 12 | it 'can sort two elements' do 13 | expect(selection_sort_recursive([3, 1])).to eq([1, 3]) 14 | end 15 | 16 | it 'can sort several elements' do 17 | expect(selection_sort_recursive([10, 4, 3, 2, 1, 5])).to eq([1, 2, 3, 4, 5, 10]) 18 | end 19 | 20 | it 'can sort negative and positive values' do 21 | expect(selection_sort_recursive([-1, -2, 4, 2])).to eq([-2, -1, 2, 4]) 22 | end 23 | 24 | it 'can sort an array containing repeating values' do 25 | expect(selection_sort_recursive([1, 4, 2, 1, 2, 4, 20, -2])).to eq([1, 4, 2, 1, 2, 4, 20, -2].sort) 26 | end 27 | end -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/solutions/benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | // Paste your iterative and recursive solutions in this file 2 | // And then calculate their average run times to compare them. 3 | function selectionSort(arr) { 4 | const sorted = []; 5 | 6 | while (arr.length > 0) { 7 | const min = Math.min(...arr); 8 | const idx = arr.indexOf(min); 9 | 10 | sorted.push(min); 11 | arr.splice(idx, 1); 12 | } 13 | 14 | return sorted; 15 | } 16 | 17 | function selectionSortRecursive(arr) { 18 | if (arr.length === 0) { 19 | return []; 20 | } 21 | 22 | const min = Math.min(...arr); 23 | const idx = arr.indexOf(min); 24 | arr.splice(idx, 1); 25 | 26 | const result = selectionSortRecursive(arr); 27 | result.unshift(min); 28 | return result; 29 | } 30 | 31 | 32 | function benchmark(callback) { 33 | const startTime = Date.now(); 34 | 35 | for (let i = 0; i < 1000; ++i) { 36 | callback(); 37 | } 38 | 39 | return (Date.now() - startTime) / 1000; 40 | } 41 | 42 | console.log('Iterative:', benchmark(() => selectionSort([2, 3, 4, 1, 4, 56, -2, 20]))); 43 | console.log('Recursive:', benchmark(() => selectionSortRecursive([2, 3, 4, 1, 4, 56, -2, 20]))); 44 | -------------------------------------------------------------------------------- /02-week-2--recursion/05-day-5--recursive-selection-sort/solutions/benchmark/benchmark.rb: -------------------------------------------------------------------------------- 1 | # Paste your iterative and recursive solutions in this file 2 | # And then calculate their average run times to compare them. 3 | def selection_sort(arr) 4 | sorted = [] 5 | 6 | until arr.length == 0 7 | min = arr.min 8 | idx = arr.index(min) 9 | sorted << min 10 | arr.delete_at(idx) 11 | end 12 | 13 | sorted 14 | end 15 | 16 | def selection_sort_recursive(arr) 17 | return [] if arr.empty? 18 | 19 | min = arr.min 20 | idx = arr.index(min) 21 | arr.delete_at(idx) 22 | 23 | result = selection_sort_recursive(arr) 24 | result.unshift(min) 25 | end 26 | 27 | def benchmark 28 | start_time = Time.now 29 | 30 | 1000.times do 31 | yield 32 | end 33 | 34 | (Time.now - start_time) / 1000 35 | end 36 | 37 | puts "Iterative: #{benchmark { selection_sort([2, 3, 4, 1, 4, 56, -2, 20]) }}" 38 | puts "Recursive: #{benchmark { selection_sort_recursive([2, 3, 4, 1, 4, 56, -2, 20]) }}" 39 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/README.md: -------------------------------------------------------------------------------- 1 | # Bonus 1: Balancing Parentheses 2 | 3 | For parentheses to be considered balanced, there must an opening parenthesis followed by a matching closing parenthesis. Given a string containing only parentheses, return the number of additional parentheses needed for the string to be considered balanced. The input string will have a minimum length of 1. 4 | 5 | ``` 6 | Input: '(()())' 7 | Output: 0 8 | 9 | Input: '()))' 10 | Output: 2 11 | 12 | Input: ')' 13 | Output: 1 14 | ``` 15 | 16 | Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code. 17 | 18 | ## Before you start coding: 19 | 20 | 1. Rewrite the problem in your own words 21 | 2. Validate that you understand the problem 22 | 3. Write your own test cases 23 | 4. Pseudocode 24 | 5. Code! 25 | 26 | **_And remember, don't run our tests until you've passed your own!_** 27 | 28 | ## How to run your own tests 29 | 30 | ### Ruby 31 | 32 | 1. `cd` into the ruby folder 33 | 2. `ruby .rb` 34 | 35 | ### JavaScript 36 | 37 | 1. `cd` into the javascript folder 38 | 2. `node .js` 39 | 40 | ## How to run our tests 41 | 42 | ### Ruby 43 | 44 | 1. `cd` into the ruby folder 45 | 2. `bundle install` 46 | 3. `rspec` 47 | 48 | ### JavaScript 49 | 50 | 1. `cd` into the javascript folder 51 | 2. `npm i` 52 | 3. `npm test` 53 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/javascript/balancing_parentheses.js: -------------------------------------------------------------------------------- 1 | function balancingParentheses(string) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 0"); 8 | console.log(balancingParentheses('(()())')); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 2"); 13 | console.log(balancingParentheses('()))')); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 1"); 18 | console.log(balancingParentheses(')')); 19 | } 20 | 21 | module.exports = balancingParentheses; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "balancing_parentheses", 3 | "version": "1.0.0", 4 | "description": "balancing_parentheses", 5 | "main": "balancing_parentheses.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/javascript/tests/balancing_parentheses.test.js: -------------------------------------------------------------------------------- 1 | const balancingParentheses = require('../balancing_parentheses'); 2 | 3 | test('can balance parentheses when only one type of parenthesis is in the string', () => { 4 | expect(balancingParentheses(')')).toBe(1); 5 | expect(balancingParentheses('(')).toBe(1); 6 | expect(balancingParentheses(')))')).toBe(3); 7 | expect(balancingParentheses('(((')).toBe(3); 8 | }); 9 | 10 | test('accounts for strings that start with a closing parenthesis or end with an opening one', () => { 11 | expect(balancingParentheses(')(')).toBe(2); 12 | expect(balancingParentheses(')()')).toBe(1); 13 | expect(balancingParentheses(')((((()))((())))()(()))(')).toBe(2); 14 | }); 15 | 16 | test('returns 0 when the parentheses are balanced', () => { 17 | expect(balancingParentheses('(()())')).toBe(0); 18 | expect(balancingParentheses('()')).toBe(0); 19 | }); 20 | 21 | 22 | test('returns the correct number when the string starts with an opening parenthesis and ends with a closing one', () => { 23 | expect(balancingParentheses('()))')).toBe(2); 24 | }); 25 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/ruby/balancing_parentheses.rb: -------------------------------------------------------------------------------- 1 | def balancing_parentheses(string) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 0" 7 | puts balancing_parentheses('(()())') 8 | 9 | puts 10 | 11 | puts "Expecting: 2" 12 | puts balancing_parentheses('()))') 13 | 14 | puts 15 | 16 | puts "Expecting: 1" 17 | puts balancing_parentheses(')') 18 | 19 | # Don't forget to add your own! 20 | end 21 | 22 | # Please add your pseudocode to this file 23 | # And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/ruby/spec/balancing_parentheses_spec.rb: -------------------------------------------------------------------------------- 1 | require './balancing_parentheses' 2 | 3 | RSpec.describe '#balancing_parentheses' do 4 | it 'can balance parentheses when only one type of parenthesis is in the string' do 5 | expect(balancing_parentheses(')')).to eq(1) 6 | expect(balancing_parentheses('(')).to eq(1) 7 | expect(balancing_parentheses(')))')).to eq(3) 8 | expect(balancing_parentheses('(((')).to eq(3) 9 | end 10 | 11 | it 'accounts for strings that start with a closing parenthesis or end with an opening one' do 12 | expect(balancing_parentheses(')(')).to eq(2) 13 | expect(balancing_parentheses(')()')).to eq(1) 14 | expect(balancing_parentheses(')((((()))((())))()(()))(')).to eq(2) 15 | end 16 | 17 | it 'returns 0 when the parentheses are balanced' do 18 | expect(balancing_parentheses('(()())')).to eq(0) 19 | expect(balancing_parentheses('()')).to eq(0) 20 | end 21 | 22 | it 'returns the correct number when the string starts with an opening parenthesis and ends with a closing one' do 23 | expect(balancing_parentheses('()))')).to eq(2) 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "roman_numeral", 3 | "version": "1.0.0", 4 | "description": "roman_numeral", 5 | "main": "roman_numeral.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/javascript/roman_numeral.js: -------------------------------------------------------------------------------- 1 | function romanNumeral(string) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 1"); 8 | console.log(romanNumeral('I')); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 9"); 13 | console.log(romanNumeral('IX')); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 402"); 18 | console.log(romanNumeral('CDII')); 19 | } 20 | 21 | module.exports = romanNumeral; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/javascript/tests/roman_numeral.test.js: -------------------------------------------------------------------------------- 1 | const romanNumeral = require('../roman_numeral'); 2 | 3 | test('handles small roman numerals', () => { 4 | expect(romanNumeral('I')).toBe(1); 5 | expect(romanNumeral('III')).toBe(3); 6 | }); 7 | 8 | test('handles instances where the smaller numeral comes before the larger one', () => { 9 | expect(romanNumeral('IX')).toBe(9); 10 | expect(romanNumeral('MCM')).toBe(1900); 11 | expect(romanNumeral('MCMXCIX')).toBe(1999); 12 | expect(romanNumeral('CDII')).toBe(402); 13 | expect(romanNumeral('XLIV')).toBe(44); 14 | }); 15 | 16 | test('handles numbers in the hundreds and low thousands', () => { 17 | expect(romanNumeral('CCXXIII')).toBe(223); 18 | expect(romanNumeral('MMMDCCCXLVIII')).toBe(3848); 19 | }); 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/ruby/roman_numeral.rb: -------------------------------------------------------------------------------- 1 | def roman_numeral(string) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 1" 7 | puts roman_numeral('I') 8 | 9 | puts 10 | 11 | puts "Expecting: 9" 12 | puts roman_numeral('IX') 13 | 14 | puts 15 | 16 | puts "Expecting: 402" 17 | puts roman_numeral('CDII') 18 | 19 | # Don't forget to add your own! 20 | end 21 | 22 | # Please add your pseudocode to this file 23 | # And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/01-bonus-2--roman-numeral-to-integer/ruby/spec/roman_numeral_spec.rb: -------------------------------------------------------------------------------- 1 | require './roman_numeral' 2 | 3 | RSpec.describe '#roman_numeral' do 4 | it 'handles small roman numerals' do 5 | expect(roman_numeral('I')).to eq(1) 6 | expect(roman_numeral('III')).to eq(3) 7 | end 8 | 9 | it 'handles instances where the smaller numeral comes before the larger one' do 10 | expect(roman_numeral('IX')).to eq(9) 11 | expect(roman_numeral('MCM')).to eq(1900) 12 | expect(roman_numeral('MCMXCIX')).to eq(1999) 13 | expect(roman_numeral('CDII')).to eq(402) 14 | expect(roman_numeral('XLIV')).to eq(44) 15 | end 16 | 17 | it 'handles numbers in the hundreds and low thousands' do 18 | expect(roman_numeral('CCXXIII')).to eq(223) 19 | expect(roman_numeral('MMMDCCCXLVIII')).to eq(3848) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/README.md: -------------------------------------------------------------------------------- 1 | # Bonus 3: Rotate Array Clockwise 2 | 3 | Given an input Array, rotate `k` units clockwise, i.e. shift the values rightward `k` units. 4 | 5 | `k` is an Integer >= 0. 6 | 7 | ``` 8 | Input: [1, 2, 3, 4], 1 9 | Output: [4, 1, 2, 3] 10 | 11 | Input: [1, 2, 3], 2 12 | Output: [2, 3, 1] 13 | 14 | Input: [1, 2, 3], 3 15 | Output: [1, 2, 3] 16 | ``` 17 | 18 | Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code. 19 | 20 | ## Before you start coding: 21 | 22 | 1. Rewrite the problem in your own words 23 | 2. Validate that you understand the problem 24 | 3. Write your own test cases 25 | 4. Pseudocode 26 | 5. Code! 27 | 28 | **_And remember, don't run our tests until you've passed your own!_** 29 | 30 | ## How to run your own tests 31 | 32 | ### Ruby 33 | 34 | 1. `cd` into the ruby folder 35 | 2. `ruby .rb` 36 | 37 | ### JavaScript 38 | 39 | 1. `cd` into the javascript folder 40 | 2. `node .js` 41 | 42 | ## How to run our tests 43 | 44 | ### Ruby 45 | 46 | 1. `cd` into the ruby folder 47 | 2. `bundle install` 48 | 3. `rspec` 49 | 50 | ### JavaScript 51 | 52 | 1. `cd` into the javascript folder 53 | 2. `npm i` 54 | 3. `npm test` 55 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rotate_array", 3 | "version": "1.0.0", 4 | "description": "rotate_array", 5 | "main": "rotate_array.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/javascript/rotate_array.js: -------------------------------------------------------------------------------- 1 | function rotateArray(arr, k) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: [4, 1, 2, 3]"); 8 | console.log("=>", rotateArray([1, 2, 3, 4], 1)); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: [2, 3, 1]"); 13 | console.log("=>", rotateArray([1, 2, 3], 2)); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: [1, 2, 3]"); 18 | console.log("=>", rotateArray([1, 2, 3], 3)); 19 | } 20 | 21 | module.exports = rotateArray; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/javascript/tests/rotate_array.test.js: -------------------------------------------------------------------------------- 1 | const rotateArray = require('../rotate_array'); 2 | 3 | test('can handle k values from 1 up to the length of the array', () => { 4 | expect(rotateArray([1, 2, 3, 4], 1)).toEqual([4, 1, 2, 3]); 5 | expect(rotateArray([1, 2, 3], 2)).toEqual([2, 3, 1]); 6 | expect(rotateArray([1, 2, 3], 3)).toEqual([1, 2, 3]); 7 | }); 8 | 9 | test('can handle an empty array', () => { 10 | expect(rotateArray([], 7)).toEqual([]); 11 | expect(rotateArray([], 0)).toEqual([]); 12 | }); 13 | 14 | test('can handle a k value of 0', () => { 15 | expect(rotateArray([1, 2, 3], 0)).toEqual([1, 2, 3]); 16 | }); 17 | 18 | test('can handle k values larger than the array length', () => { 19 | expect(rotateArray([1, 2, 3], 5)).toEqual([2, 3, 1]); 20 | expect(rotateArray([1, 2, 3], 6)).toEqual([1, 2, 3]); 21 | expect(rotateArray([1, 2, 3, 4], 41)).toEqual([4, 1, 2, 3]); 22 | }); 23 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/ruby/rotate_array.rb: -------------------------------------------------------------------------------- 1 | def rotate_array(arr, k) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: [4, 1, 2, 3]" 7 | print "=> " 8 | print rotate_array([1, 2, 3, 4], 1) 9 | 10 | puts 11 | 12 | puts "Expecting: [2, 3, 1]" 13 | print "=> " 14 | print rotate_array([1, 2, 3], 2) 15 | 16 | puts 17 | 18 | puts "Expecting: [1, 2, 3]" 19 | print "=> " 20 | print rotate_array([1, 2, 3], 3) 21 | # Don't forget to add your own! 22 | end 23 | 24 | # Please add your pseudocode to this file 25 | # And a written explanation of your solution 26 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/02-bonus-3--rotate-array-clockwise/ruby/spec/rotate_array_spec.rb: -------------------------------------------------------------------------------- 1 | require './rotate_array' 2 | 3 | RSpec.describe '#rotate_array' do 4 | it 'can handle k values from 1 up to the length of the array' do 5 | expect(rotate_array([1, 2, 3, 4], 1)).to eq([4, 1, 2, 3]) 6 | expect(rotate_array([1, 2, 3], 2)).to eq([2, 3, 1]) 7 | expect(rotate_array([1, 2, 3], 3)).to eq([1, 2, 3]) 8 | end 9 | 10 | it 'can handle an empty array' do 11 | expect(rotate_array([], 7)).to eq([]) 12 | expect(rotate_array([], 0)).to eq([]) 13 | end 14 | 15 | it 'can handle a k value of 0' do 16 | expect(rotate_array([1, 2, 3], 0)).to eq([1, 2, 3]) 17 | end 18 | 19 | it 'can handle k values larger than the array length' do 20 | expect(rotate_array([1, 2, 3], 5)).to eq([2, 3, 1]) 21 | expect(rotate_array([1, 2, 3], 6)).to eq([1, 2, 3]) 22 | expect(rotate_array([1, 2, 3, 4], 41)).to eq([4, 1, 2, 3]) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/README.md: -------------------------------------------------------------------------------- 1 | # Bonus 4: Distinct Pair Sum 2 | 3 | Given an input Array and a target value `k`, return all distinct pairs of consecutive numbers that add up to `k`. A pair is distinct if no other pair contains the same numbers. The order of the pairs and order of the values in each pair does not matter, e.g. we consider [[2, 8], [7, 3]] to be the same as [[3, 7], [8, 2]]. 4 | 5 | ``` 6 | Input: [0, 1, 1, 2, 0, 1, 1], 2 7 | Output: [[1, 1], [2, 0]] 8 | 9 | Input: [3, 4, 2, 1, 5, 2, 8, 2], 10 10 | Output: [[2, 8]] 11 | ``` 12 | 13 | Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code. 14 | 15 | ## Before you start coding: 16 | 17 | 1. Rewrite the problem in your own words 18 | 2. Validate that you understand the problem 19 | 3. Write your own test cases 20 | 4. Pseudocode 21 | 5. Code! 22 | 23 | **_And remember, don't run our tests until you've passed your own!_** 24 | 25 | ## How to run your own tests 26 | 27 | ### Ruby 28 | 29 | 1. `cd` into the ruby folder 30 | 2. `ruby .rb` 31 | 32 | ### JavaScript 33 | 34 | 1. `cd` into the javascript folder 35 | 2. `node .js` 36 | 37 | ## How to run our tests 38 | 39 | ### Ruby 40 | 41 | 1. `cd` into the ruby folder 42 | 2. `bundle install` 43 | 3. `rspec` 44 | 45 | ### JavaScript 46 | 47 | 1. `cd` into the javascript folder 48 | 2. `npm i` 49 | 3. `npm test` 50 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/javascript/distinct_pair_sum.js: -------------------------------------------------------------------------------- 1 | function distinctPairSum(arr, k) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: [[1, 1], [2, 0]]"); 8 | console.log("=>", distinctPairSum([0, 1, 1, 2, 0, 1, 1], 2)); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: [[2, 8]]"); 13 | console.log("=>", distinctPairSum([3, 4, 2, 1, 5, 2, 8, 2], 10)); 14 | } 15 | 16 | module.exports = distinctPairSum; 17 | 18 | // Please add your pseudocode to this file 19 | // And a written explanation of your solution 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "distinct_pair_sum.js", 3 | "version": "1.0.0", 4 | "description": "distinct_pair_sum.js", 5 | "main": "distinct_pair_sum.js.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/javascript/tests/distinct_pair_sum.test.js: -------------------------------------------------------------------------------- 1 | const distinctPairSum = require('../distinct_pair_sum'); 2 | 3 | function sortArray(arr, k) { 4 | let res = distinctPairSum(arr, k); 5 | res = res.map(arr => arr.sort((a, b) => a - b)); 6 | return res.sort((a, b) => a[0] - b[0]); 7 | } 8 | 9 | test('returns an empty array when there are no pairs that sum up to k', () => { 10 | expect(distinctPairSum([3, 4, 2, 1, 5, 2, 8, 2], 100)).toEqual([]); 11 | expect(distinctPairSum([3, 4, 2, 1, 5, 2, 8, 2], 100).length).toBe(0); 12 | expect(distinctPairSum([], 100).length).toBe(0); 13 | expect(distinctPairSum([59], 100).length).toBe(0); 14 | }); 15 | 16 | test('only returns distinct pairs', () => { 17 | expect(sortArray([0, 1, 1, 2, 0, 1, 1], 2)).toEqual([[0, 2], [1, 1]]); 18 | expect(sortArray([3, 4, 2, 1, 5, 2, 8, 2], 10)).toEqual([[2, 8]]); 19 | expect(sortArray([59, 41], 100)).toEqual([[41, 59]]); 20 | expect(sortArray([1, 0, 0, 10, -10, 5, 4, 3, -3, -3], 0)).toEqual([[-10, 10], [-3, 3], [0, 0]]); 21 | }); 22 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/ruby/distinct_pair_sum.rb: -------------------------------------------------------------------------------- 1 | def distinct_pair_sum(arr, k) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: [[1, 1], [2, 0]]" 7 | print "=> " 8 | print distinct_pair_sum([0, 1, 1, 2, 0, 1, 1], 2) 9 | 10 | puts 11 | 12 | puts "Expecting: [[2, 8]]" 13 | print "=> " 14 | print distinct_pair_sum([3, 4, 2, 1, 5, 2, 8, 2], 10) 15 | 16 | # Don't forget to add your own! 17 | end 18 | 19 | # Please add your pseudocode to this file 20 | # And a written explanation of your solution 21 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/03-bonus-4--distinct-pair-sum/ruby/spec/distinct_pair_sum_spec.rb: -------------------------------------------------------------------------------- 1 | require './distinct_pair_sum' 2 | 3 | def sort_array(arr, k) 4 | res = distinct_pair_sum(arr, k) 5 | res.map!(&:sort) 6 | res.sort! 7 | end 8 | 9 | RSpec.describe '#distinct_pair_sum' do 10 | it 'returns an empty array when there are no pairs that sum up to k' do 11 | expect(distinct_pair_sum([3, 4, 2, 1, 5, 2, 8, 2], 100)).to eq([]) 12 | expect(distinct_pair_sum([], 100)).to eq([]) 13 | expect(distinct_pair_sum([59], 100)).to eq([]) 14 | end 15 | 16 | it 'only returns distinct pairs' do 17 | expect(sort_array([0, 1, 1, 2, 0, 1, 1], 2)).to eq([[0, 2], [1, 1]]) 18 | expect(sort_array([3, 4, 2, 1, 5, 2, 8, 2], 10)).to eq([[2, 8]]) 19 | expect(sort_array([59, 41], 100)).to eq([[41, 59]]) 20 | expect(sort_array([1, 0, 0, 10, -10, 5, 4, 3, -3, -3], 0)).to eq([[-10, 10], [-3, 3], [0, 0]]) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/README.md: -------------------------------------------------------------------------------- 1 | # Bonus 5: Consecutive Substrings 2 | 3 | Given a string, return all consecutive substrings within that string consisting of at least one character. Substrings should be returned in the order in which they appear. 4 | 5 | Note than in the string 'abc', 'ac' is not a consecutive substring. 6 | 7 | The input string will have a length of 0 or more. 8 | 9 | ``` 10 | Input: 'abc' 11 | Output: ['a', 'ab', 'abc', 'b', 'bc', 'c'] 12 | 13 | Input: 'a' 14 | Output: ['a'] 15 | ``` 16 | 17 | Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code. 18 | 19 | ## Before you start coding: 20 | 21 | 1. Rewrite the problem in your own words 22 | 2. Validate that you understand the problem 23 | 3. Write your own test cases 24 | 4. Pseudocode 25 | 5. Code! 26 | 27 | **_And remember, don't run our tests until you've passed your own!_** 28 | 29 | ## How to run your own tests 30 | 31 | ### Ruby 32 | 33 | 1. `cd` into the ruby folder 34 | 2. `ruby .rb` 35 | 36 | ### JavaScript 37 | 38 | 1. `cd` into the javascript folder 39 | 2. `node .js` 40 | 41 | ## How to run our tests 42 | 43 | ### Ruby 44 | 45 | 1. `cd` into the ruby folder 46 | 2. `bundle install` 47 | 3. `rspec` 48 | 49 | ### JavaScript 50 | 51 | 1. `cd` into the javascript folder 52 | 2. `npm i` 53 | 3. `npm test` 54 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/javascript/consecutive_substrings.js: -------------------------------------------------------------------------------- 1 | function consecutiveSubstrings(string) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: ['a', 'ab', 'abc', 'b', 'bc', 'c']"); 8 | console.log("=>", consecutiveSubstrings('abc')); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: ['a']"); 13 | console.log("=>", consecutiveSubstrings('a')); 14 | } 15 | 16 | module.exports = consecutiveSubstrings; 17 | 18 | // Please add your pseudocode to this file 19 | // And a written explanation of your solution 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "consecutive_substrings", 3 | "version": "1.0.0", 4 | "description": "consecutive_substrings", 5 | "main": "consecutive_substrings.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/javascript/tests/consecutive_substrings.test.js: -------------------------------------------------------------------------------- 1 | const consecutiveSubstrings = require('../consecutive_substrings'); 2 | 3 | test('returns an empty array when the input string is empty', () => { 4 | expect(consecutiveSubstrings('').length).toBe(0); 5 | }); 6 | 7 | test('returns an array containing one string when the input is one character', () => { 8 | expect(consecutiveSubstrings('a')).toEqual(['a']); 9 | }); 10 | 11 | test('can handle many letters', () => { 12 | expect(consecutiveSubstrings('ab')).toEqual(['a', 'ab', 'b']); 13 | expect(consecutiveSubstrings('abc')).toEqual(['a', 'ab', 'abc', 'b', 'bc', 'c']); 14 | }); 15 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/ruby/consecutive_substrings.rb: -------------------------------------------------------------------------------- 1 | def consecutive_substrings(string) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: ['a', 'ab', 'abc', 'b', 'bc', 'c']" 7 | print "=> " 8 | print consecutive_substrings('abc') 9 | 10 | puts 11 | 12 | puts "Expecting: ['a']" 13 | print "=> " 14 | print consecutive_substrings('a') 15 | 16 | # Don't forget to add your own! 17 | end 18 | 19 | # Please add your pseudocode to this file 20 | # And a written explanation of your solution 21 | -------------------------------------------------------------------------------- /03-week-3--additional-practice/04-bonus-5--consecutive-substrings/ruby/spec/consecutive_substrings_spec.rb: -------------------------------------------------------------------------------- 1 | require './consecutive_substrings' 2 | 3 | RSpec.describe '#consecutive_substrings' do 4 | it 'returns an empty array when the input string is empty' do 5 | expect(consecutive_substrings('')).to eq([]) 6 | end 7 | 8 | it 'returns an array containing one string when the input is one character' do 9 | expect(consecutive_substrings('a')).to eq(['a']) 10 | end 11 | 12 | it 'can handle many letters' do 13 | expect(consecutive_substrings('ab')).to eq(['a', 'ab', 'b']) 14 | expect(consecutive_substrings('abc')).to eq(['a', 'ab', 'abc', 'b', 'bc', 'c']) 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /05-week-4--big-o-notation/00-day-1--introduction-to-big-o-notation/Big-O-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/05-week-4--big-o-notation/00-day-1--introduction-to-big-o-notation/Big-O-graph.png -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stack", 3 | "version": "1.0.0", 4 | "description": "stack class", 5 | "main": "stack.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/javascript/stack.js: -------------------------------------------------------------------------------- 1 | class Stack { 2 | constructor() { 3 | this.stack = []; 4 | // this is an arbitrary value to make testing easier 5 | // 1,024 would be way too high to test! 6 | this.limit = 10; 7 | } 8 | 9 | // add item to top of stack if not full 10 | // if full throw error 11 | push(item) { 12 | 13 | } 14 | 15 | // remove item from top of stack and return it 16 | pop() { 17 | 18 | } 19 | 20 | // return item at top of stack without removing it 21 | peek() { 22 | 23 | } 24 | 25 | // return true if stack is empty, otherwise false 26 | isEmpty() { 27 | 28 | } 29 | 30 | // return true if stack is full, otherwise false 31 | isFull() { 32 | 33 | } 34 | 35 | // return number of items in stack 36 | size() { 37 | 38 | } 39 | 40 | // return -1 if item not in stack, otherwise integer representing 41 | // how far it is from the top 42 | search(target) { 43 | 44 | } 45 | 46 | // print contents of stack: do not return the stack itself! 47 | print() { 48 | 49 | } 50 | } 51 | 52 | if (require.main === module) { 53 | // add your own tests in here 54 | } 55 | 56 | module.exports = Stack; 57 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/pancakes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/pancakes.png -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/00-days-1-to-2--implement-a-stack-class/ruby/stack.rb: -------------------------------------------------------------------------------- 1 | class Stack 2 | attr_reader :limit 3 | 4 | def initialize 5 | @stack = [] 6 | # this is an arbitrary value to make testing easier 7 | # 1,024 would be way too high to test! 8 | @limit = 10 9 | end 10 | 11 | # add item to top of stack if not full 12 | # if full, throw error 13 | def push(item) 14 | end 15 | 16 | # remove item from top of stack and return it 17 | def pop 18 | end 19 | 20 | # return item at top of stack without removing it 21 | def peek 22 | end 23 | 24 | # return true if stack is empty, otherwise false 25 | def isEmpty? 26 | end 27 | 28 | # return true if stack is full, otherwise false 29 | def isFull? 30 | end 31 | 32 | # return number of items in stack 33 | def size 34 | end 35 | 36 | # return -1 if item not in stack, otherwise integer representing 37 | # how far it is from the top 38 | def search(target) 39 | end 40 | 41 | # print contents of stack: do not return the stack itself! 42 | def print 43 | end 44 | end 45 | 46 | if __FILE__ == $PROGRAM_NAME 47 | # Don't forget to add your tests! 48 | end 49 | 50 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/grocery_store.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/grocery_store.jpg -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "queue", 3 | "version": "1.0.0", 4 | "description": "queue class", 5 | "main": "queue.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/javascript/queue.js: -------------------------------------------------------------------------------- 1 | class Queue { 2 | constructor() { 3 | this.queue = []; 4 | // this is an arbitrary value to make testing easier 5 | // 1,024 would be way too high to test! 6 | this.limit = 10; 7 | } 8 | 9 | // add item to rear of queue if not full 10 | // if full throw error 11 | enqueue(item) { 12 | 13 | } 14 | 15 | // remove item from front of queue and return it 16 | dequeue() { 17 | 18 | } 19 | 20 | // return item at front of queue without removing it 21 | peek() { 22 | 23 | } 24 | 25 | // return true if queue is empty, otherwise false 26 | isEmpty() { 27 | 28 | } 29 | 30 | // return true if queue is full, otherwise false 31 | isFull() { 32 | 33 | } 34 | 35 | // return number of items in queue 36 | size() { 37 | 38 | } 39 | 40 | // return -1 if item not in queue, otherwise integer representing 41 | // how far it is from the front 42 | search(target) { 43 | 44 | } 45 | 46 | // print contents of queue: do not return the queue itself! 47 | print() { 48 | 49 | } 50 | } 51 | 52 | if (require.main === module) { 53 | // add your own tests in here 54 | } 55 | 56 | module.exports = Queue; 57 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/01-days-3-to-4--implement-a-queue-class/ruby/queue.rb: -------------------------------------------------------------------------------- 1 | class Queue 2 | attr_reader :limit 3 | 4 | def initialize 5 | @queue = [] 6 | # this is an arbitrary value to make testing easier 7 | # 1,024 would be way too high to test! 8 | @limit = 10 9 | end 10 | 11 | # add item to rear of queue if not full 12 | # if full, throw error 13 | def enqueue(item) 14 | end 15 | 16 | # remove item from front of queue and return it 17 | def dequeue 18 | end 19 | 20 | # return item at front of queue without removing it 21 | def peek 22 | end 23 | 24 | # return true if queue is empty, otherwise false 25 | def isEmpty? 26 | end 27 | 28 | # return true if queue is full, otherwise false 29 | def isFull? 30 | end 31 | 32 | # return number of items in queue 33 | def size 34 | end 35 | 36 | # return -1 if item not in queue, otherwise integer representing 37 | # how far it is from the front 38 | def search(target) 39 | end 40 | 41 | # print contents of queue: do not return the queue itself! 42 | def print 43 | end 44 | end 45 | 46 | if __FILE__ == $PROGRAM_NAME 47 | # Don't forget to add your tests! 48 | end 49 | 50 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/02-day-5--implement-a-set/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /06-week-5--big-o-continued/02-day-5--implement-a-set/javascript/my_set.js: -------------------------------------------------------------------------------- 1 | class MySet { 2 | // throw an error if called with anything other than string, array or nothing 3 | // if an iterable is provided only its unique values should be in data 4 | // strings and arrays will need to be broken down by their elements/characters 5 | constructor(iterable) { 6 | this.data = {}; 7 | } 8 | 9 | // return number of elements in MySet 10 | size() { 11 | 12 | } 13 | 14 | // add an item to MySet as is 15 | // don't worry about arrays here! 16 | // return the MySet instance 17 | add(item) { 18 | 19 | } 20 | 21 | // delete an item from MySet 22 | // don't worry about arrays here! 23 | // return true if successful, otherwise false 24 | delete(item) { 25 | 26 | } 27 | 28 | // return true if in MySet, otherwise false 29 | // don't worry about arrays here! 30 | has(item) { 31 | 32 | } 33 | 34 | // return data as an array 35 | // don't worry about arrays here! 36 | entries() { 37 | 38 | } 39 | } 40 | 41 | if (require.main === module) { 42 | // add your own tests in here 43 | 44 | } 45 | 46 | module.exports = MySet; 47 | 48 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/02-day-5--implement-a-set/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myset", 3 | "version": "1.0.0", 4 | "description": "set class", 5 | "main": "my_set.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/02-day-5--implement-a-set/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/02-day-5--implement-a-set/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /06-week-5--big-o-continued/02-day-5--implement-a-set/ruby/my_set.rb: -------------------------------------------------------------------------------- 1 | class MySet 2 | attr_reader :data 3 | # throw an error if called with anything other than string, array or nothing 4 | # if an iterable is provided only its unique values should be in data 5 | # strings and arrays will need to be broken down by their elements/characters 6 | def initialize(iterable = nil) 7 | @data = {} 8 | end 9 | 10 | # return number of elements in MySet 11 | def size 12 | end 13 | 14 | # add an item to MySet as is 15 | # return the MySet instance 16 | def add(item) 17 | end 18 | 19 | # delete an item from MySet 20 | # return true if successful otherwise false 21 | def delete(item) 22 | end 23 | 24 | # return true if in MySet, otherwise false 25 | def has(item) 26 | end 27 | 28 | # return data as an array 29 | def entries 30 | end 31 | end 32 | 33 | if __FILE__ == $PROGRAM_NAME 34 | # Don't forget to add your own! 35 | end 36 | 37 | 38 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/00-days-1-to-2--implement-a-linked-list/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/00-days-1-to-2--implement-a-linked-list/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linked_list", 3 | "version": "1.0.0", 4 | "description": "linked list", 5 | "main": "linked_list.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/00-days-1-to-2--implement-a-linked-list/linked_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/07-week-6--foundational-data-structures/00-days-1-to-2--implement-a-linked-list/linked_list.png -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/00-days-1-to-2--implement-a-linked-list/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/00-days-1-to-2--implement-a-linked-list/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/README.md: -------------------------------------------------------------------------------- 1 | # Bonus Algorithm: Recursive Reverse a String 2 | 3 | For this task, you'll need to reverse a string...**recursively**! Your method will receive one argument, a string, and be expected to output that string with its letters in reverse order. 4 | 5 | ``` 6 | Input: "hi" 7 | Output: "ih" 8 | 9 | Input: "catbaby" 10 | Output: "ybabtac" 11 | ``` 12 | 13 | **Do not call any type of built-in reverse method!** 14 | 15 | Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code. 16 | 17 | ## Before you start coding: 18 | 19 | 1. Rewrite the problem in your own words 20 | 2. Validate that you understand the problem 21 | 3. Write your own test cases 22 | 4. Pseudocode 23 | 5. Code! 24 | 25 | **_And remember, don't run our tests until you've passed your own!_** 26 | 27 | ## How to run your own tests 28 | 29 | ### Ruby 30 | 31 | 1. `cd` into the ruby folder 32 | 2. `ruby .rb` 33 | 34 | ### JavaScript 35 | 36 | 1. `cd` into the javascript folder 37 | 2. `node .js` 38 | 39 | ## How to run our tests 40 | 41 | ### Ruby 42 | 43 | 1. `cd` into the ruby folder 44 | 2. `bundle install` 45 | 3. `rspec` 46 | 47 | ### JavaScript 48 | 49 | 1. `cd` into the javascript folder 50 | 2. `npm i` 51 | 3. `npm test` 52 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reverse_string", 3 | "version": "1.0.0", 4 | "description": "reverse a string", 5 | "main": "reverse_string.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/javascript/reverse_string.js: -------------------------------------------------------------------------------- 1 | function reverseString(str) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 'ih'"); 8 | console.log("=>", reverseString('ih')); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 'ybabtac'"); 13 | console.log("=>", reverseString('catbaby')); 14 | } 15 | 16 | module.exports = reverseString; 17 | 18 | // Please add your pseudocode to this file 19 | // And a written explanation of your solution 20 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/javascript/tests/reverse_string.test.js: -------------------------------------------------------------------------------- 1 | const reverseString = require('../reverse_string'); 2 | 3 | test("can handle an empty string", () => { 4 | expect(reverseString("")).toBe(""); 5 | }); 6 | 7 | test("can handle a single character", () => { 8 | expect(reverseString("a")).toBe("a"); 9 | }); 10 | 11 | test("can handle two characters", () => { 12 | expect(reverseString("ab")).toBe("ba"); 13 | }); 14 | 15 | test("can handle three characters", () => { 16 | expect(reverseString("cat")).toBe("tac"); 17 | }); 18 | 19 | test("can handle many characters", () => { 20 | expect(reverseString("sham-meow")).toBe("sham-meow".split("").reverse().join("")); 21 | }); 22 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/ruby/reverse_string.rb: -------------------------------------------------------------------------------- 1 | def reverse_string(str) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: 'ih'" 7 | puts "=>", reverse_string('hi') 8 | 9 | puts 10 | 11 | puts "Expecting: 'ybabtac'" 12 | puts "=>", reverse_string('catbaby') 13 | 14 | # Don't forget to add your own! 15 | end 16 | 17 | # Please add your pseudocode to this file 18 | # And a written explanation of your solution -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/03-bonus-algorithm--recursive-string-reverse/ruby/spec/reverse_string_spec.rb: -------------------------------------------------------------------------------- 1 | require './reverse_string' 2 | 3 | RSpec.describe '#reverse_string' do 4 | it "can handle an empty string" do 5 | expect(reverse_string('')).to eq('') 6 | end 7 | 8 | it "can handle a single character" do 9 | expect(reverse_string('a')).to eq('a') 10 | end 11 | 12 | it "can handle two characters" do 13 | expect(reverse_string('ab')).to eq('ba') 14 | end 15 | 16 | it "can handle three characters" do 17 | expect(reverse_string('cat')).to eq('tac') 18 | end 19 | 20 | it "can handle many characters" do 21 | expect(reverse_string('sham-meow')).to eq('sham-meow'.reverse) 22 | end 23 | end -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/04-bonus--modify-linked-list-to-track-tail-and-size/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/04-bonus--modify-linked-list-to-track-tail-and-size/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linked_list", 3 | "version": "1.0.0", 4 | "description": "linked list", 5 | "main": "linked_list.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/04-bonus--modify-linked-list-to-track-tail-and-size/linked_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/07-week-6--foundational-data-structures/04-bonus--modify-linked-list-to-track-tail-and-size/linked_list.png -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/04-bonus--modify-linked-list-to-track-tail-and-size/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/04-bonus--modify-linked-list-to-track-tail-and-size/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/05-bonus--build-a-doubly-linked-list/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/05-bonus--build-a-doubly-linked-list/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "doubly_linked_list", 3 | "version": "1.0.0", 4 | "description": "doubly linked list", 5 | "main": "doubly_linked_list.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/05-bonus--build-a-doubly-linked-list/linked_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/07-week-6--foundational-data-structures/05-bonus--build-a-doubly-linked-list/linked_list.png -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/05-bonus--build-a-doubly-linked-list/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /07-week-6--foundational-data-structures/05-bonus--build-a-doubly-linked-list/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /08-pairing-exercise-2/00-whiteboard-big-o/README.md: -------------------------------------------------------------------------------- 1 | # Whiteboard Big O 2 | 3 | ## Introduction 4 | 5 | For this activity, you and your partner will take turns calculating the time 6 | complexity using Big O notation for a problem you solved previously. Think of 7 | this exercise as being more collaborative and less formal than other 8 | whiteboarding exercises. In other words, you and your partner should communicate 9 | freely and work together to come up with the appropriate calculation. 10 | 11 | ## Instructions 12 | 13 | - You and your partner should each choose a different problem that you've 14 | already solved 15 | - Share your solution to the chosen problem either on a whiteboard or via a 16 | screenshare 17 | - Determine the time complexity for your solution 18 | - Explain your thinking and work with your partner to come up with the answer 19 | - Take turns typing or whiteboarding 20 | - Plan to start the conversation and whiteboard/type when evaluating your 21 | own solution 22 | - Remember to use the correct notation, e.g. O(n) or O(1) 23 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/javascript/bubble_sort.js: -------------------------------------------------------------------------------- 1 | function bubbleSort(arr) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: [1, 2, 3, 4]"); 8 | console.log("=>", bubbleSort([3, 2, 1, 4])); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: [1, 2, 3]"); 13 | console.log("=>", bubbleSort([1, 2, 3])); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: []"); 18 | console.log("=>", bubbleSort([])); 19 | 20 | console.log(""); 21 | 22 | console.log("Expecting: [1, 2, 3]"); 23 | console.log("=>", bubbleSort([2, 3, 1])); 24 | } 25 | 26 | module.exports = bubbleSort; 27 | 28 | // Please add your pseudocode to this file 29 | // And a written explanation of your solution 30 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bubble_sort", 3 | "version": "1.0.0", 4 | "description": "bubble sort", 5 | "main": "bubble_sort.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/javascript/tests/bubble_sort.test.js: -------------------------------------------------------------------------------- 1 | const bubbleSort = require("../bubble_sort"); 2 | 3 | test("returns the provided empty Array when it's provided as an argument", () => { 4 | const input = []; 5 | 6 | expect(bubbleSort(input)).toBe(input); 7 | expect(bubbleSort(input)).toStrictEqual([]); 8 | }); 9 | 10 | test("can handle an Array containing a single element", () => { 11 | const input = [4]; 12 | 13 | expect(bubbleSort(input)).toBe(input); 14 | expect(bubbleSort(input)).toStrictEqual([4]); 15 | }); 16 | 17 | test("can handle an Array containing two elements", () => { 18 | const input = [5, 2]; 19 | 20 | expect(bubbleSort(input)).toBe(input); 21 | expect(bubbleSort(input)).toStrictEqual([2, 5]); 22 | }); 23 | 24 | test("can handle an Array containing three elements", () => { 25 | const input = [5, 2, 1]; 26 | 27 | expect(bubbleSort(input)).toBe(input); 28 | expect(bubbleSort(input)).toStrictEqual([1, 2, 5]); 29 | }); 30 | 31 | test("can handle an Array containing many elements", () => { 32 | const input = [6, -2, 0, 8, 7, 8, 6, 0, 5, 1]; 33 | 34 | expect(bubbleSort(input)).toBe(input); 35 | expect(bubbleSort(input)).toStrictEqual([-2, 0, 0, 1, 5, 6, 6, 7, 8, 8]); 36 | }); 37 | 38 | test("can handle a sorted Array", () => { 39 | expect(bubbleSort([-10, 1, 2, 3, 4])).toStrictEqual([-10, 1, 2, 3, 4]); 40 | }); 41 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/ruby/bubble_sort.rb: -------------------------------------------------------------------------------- 1 | def bubble_sort(arr) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | puts "Expecting: [1, 2, 3, 4]" 7 | print "=> " 8 | print bubble_sort([3, 2, 1, 4]) 9 | 10 | puts 11 | 12 | puts "Expecting: [1, 2, 3]" 13 | print "=> " 14 | print bubble_sort([1, 2, 3]) 15 | 16 | puts 17 | 18 | puts "Expecting: []" 19 | print "=> " 20 | print bubble_sort([]) 21 | 22 | puts 23 | 24 | puts "Expecting: [1, 2, 3]" 25 | print "=> " 26 | print bubble_sort([2, 3, 1]) 27 | 28 | # Don't forget to add your own! 29 | end 30 | 31 | # Please add your pseudocode to this file 32 | # And a written explanation of your solution 33 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/00-days-1-to-2--bubble-sort/ruby/spec/bubble_sort_spec.rb: -------------------------------------------------------------------------------- 1 | require "./bubble_sort.rb" 2 | 3 | RSpec.describe "bubble_sort" do 4 | it "returns the provided empty Array when it's provided as an argument" do 5 | input = [] 6 | 7 | expect(bubble_sort(input)).to be(input) 8 | end 9 | 10 | it "returns an empty Array when the given an empty Array as an argument" do 11 | expect(bubble_sort([])).to eq([]) 12 | end 13 | 14 | it "can handle an Array containing a single element" do 15 | input = [4] 16 | 17 | expect(bubble_sort(input)).to be(input) 18 | expect(bubble_sort(input)).to eq([4]) 19 | end 20 | 21 | it "can handle an Array containing two elements" do 22 | input = [5, 2] 23 | 24 | expect(bubble_sort(input)).to be(input) 25 | expect(bubble_sort(input)).to eq([2, 5]) 26 | end 27 | 28 | it "can handle an Array containing three elements" do 29 | input = [5, 2, 1] 30 | 31 | expect(bubble_sort(input)).to be(input) 32 | expect(bubble_sort(input)).to eq([1, 2, 5]) 33 | end 34 | 35 | it "can handle an Array containing many elements" do 36 | input = [6, -2, 0, 8, 7, 8, 6, 0, 5, 1] 37 | 38 | expect(bubble_sort(input)).to be(input) 39 | expect(bubble_sort(input)).to eq([-2, 0, 0, 1, 5, 6, 6, 7, 8, 8]) 40 | end 41 | 42 | it "can handle a sorted Array" do 43 | expect(bubble_sort([-10, 1, 2, 3, 4])).to eq([-10, 1, 2, 3, 4]) 44 | end 45 | end -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/javascript/merge_sort.js: -------------------------------------------------------------------------------- 1 | function merge(arr1, arr2) { 2 | // type your code here 3 | } 4 | 5 | function mergeSort(arr) { 6 | // type your code here 7 | } 8 | 9 | if (require.main === module) { 10 | // add your own tests in here 11 | console.log("Expecting: [1, 2]"); 12 | console.log("=>", mergeSort([2, 1])); 13 | 14 | console.log(""); 15 | 16 | console.log("Expecting: [1, 2, 3]"); 17 | console.log("=>", mergeSort([1, 2, 3])); 18 | 19 | console.log(""); 20 | 21 | console.log("Expecting: [-10, 0, 2, 2, 5, 10, 20]"); 22 | console.log("=>", mergeSort([10, -10, 0, 2, 20, 5, 2])); 23 | } 24 | 25 | module.exports = mergeSort; 26 | 27 | // Please add your pseudocode to this file 28 | // And a written explanation of your solution 29 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "merge_sort", 3 | "version": "1.0.0", 4 | "description": "merge sort", 5 | "main": "merge_sort.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/javascript/tests/merge_sort.test.js: -------------------------------------------------------------------------------- 1 | const mergeSort = require("../merge_sort"); 2 | 3 | test("can sort an empty Array", () => { 4 | expect(mergeSort([])).toEqual([]); 5 | }); 6 | 7 | test("can sort an Array with one element", () => { 8 | expect(mergeSort([2])).toEqual([2]); 9 | }); 10 | 11 | test("can sort an Array with two elements", () => { 12 | expect(mergeSort([5, 3])).toEqual([3, 5]); 13 | }); 14 | 15 | test("can sort an Array with three elements", () => { 16 | expect(mergeSort([10, -1, 5])).toEqual([-1, 5, 10]); 17 | }); 18 | 19 | test("can sort a large Array with an even number of elements", () => { 20 | const arr = [90, 4, 5, -100, 5, 78, 3, 19, 1000, -900, 54, 34, 3, 5]; 21 | 22 | expect(mergeSort(arr)).toEqual(arr.sort((a, b) => a - b)); 23 | }); 24 | 25 | test("can sort a large Array with an odd number of elements", () => { 26 | const arr = [90, 4, 5, -100, 5, 78, 19, 1000, -900, 54, 34, 3, 5]; 27 | 28 | expect(mergeSort(arr)).toEqual(arr.sort((a, b) => a - b)); 29 | }); 30 | 31 | test("can handle an already sorted Array", () => { 32 | const arr = [-10, -5, 4, 6, 7]; 33 | 34 | expect(mergeSort(arr)).toEqual(arr); 35 | }); 36 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/merge_sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/merge_sort.gif -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/merge_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/merge_sort.png -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/ruby/merge_sort.rb: -------------------------------------------------------------------------------- 1 | def merge(arr1, arr2) 2 | # type your code in here 3 | end 4 | 5 | def merge_sort(arr) 6 | # type your code in here 7 | end 8 | 9 | if __FILE__ == $PROGRAM_NAME 10 | puts "Expecting: [1, 2]" 11 | puts "=>", merge_sort([2, 1]) 12 | 13 | puts 14 | 15 | puts "Expecting: [1, 2, 3]" 16 | puts "=>", merge_sort([1, 2, 3]) 17 | 18 | puts 19 | 20 | puts "Expecting: [-10, 0, 2, 2, 5, 10, 20]" 21 | puts "=>", merge_sort([10, -10, 0, 2, 20, 5, 2]) 22 | 23 | # Don't forget to add your own! 24 | end 25 | 26 | # Please add your pseudocode to this file 27 | # And a written explanation of your solution 28 | -------------------------------------------------------------------------------- /09-week-7--sorting-algorithms/01-days-3-to-5--merge-sort/ruby/spec/merge_sort_spec.rb: -------------------------------------------------------------------------------- 1 | require "./merge_sort.rb" 2 | 3 | RSpec.describe "merge_sort" do 4 | it "can sort an empty Array" do 5 | expect(merge_sort([])).to eq([]) 6 | end 7 | 8 | it "can sort an Array with one element" do 9 | expect(merge_sort([2])).to eq([2]) 10 | end 11 | 12 | it "can sort an Array with two elements" do 13 | expect(merge_sort([5, 3])).to eq([3, 5]) 14 | end 15 | 16 | it "can sort an Array with three elements" do 17 | expect(merge_sort([10, -1, 5])).to eq([-1, 5, 10]) 18 | end 19 | 20 | it "can sort a large Array with an even number of elements" do 21 | arr = [90, 4, 5, -100, 5, 78, 3, 19, 1000, -900, 54, 34, 3, 5] 22 | 23 | expect(merge_sort(arr)).to eq(arr.sort) 24 | end 25 | 26 | it "can sort a large Array with an odd number of elements" do 27 | arr = [90, 4, 5, -100, 5, 78, 19, 1000, -900, 54, 34, 3, 5] 28 | 29 | expect(merge_sort(arr)).to eq(arr.sort) 30 | end 31 | 32 | it "can handle an already sorted Array" do 33 | arr = [-10, -5, 4, 6, 7] 34 | 35 | expect(merge_sort(arr)).to eq(arr) 36 | end 37 | end -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/binary_search.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/00-days-1-to-3--binary-search/binary_search.gif -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/javascript/binary_search.js: -------------------------------------------------------------------------------- 1 | function binarySearch(arr, target) { 2 | // type your code here 3 | } 4 | 5 | // BONUS: MODIFY YOUR CODE TO RETURN THE INDEX OF THE TARGET, -1 IF NOT FOUND 6 | function binarySearchIndex(arr, target) { 7 | 8 | } 9 | 10 | if (require.main === module) { 11 | // add your own tests in here 12 | console.log("Expecting: true"); 13 | console.log("=>", binarySearch([1, 2, 3], 3)); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: false"); 18 | console.log("=>", binarySearch([3, 5, 9], 10)); 19 | 20 | // UNCOMMENT FOR BONUS 21 | // console.log(""); 22 | // console.log("Expecting: 0"); 23 | // console.log("=>", binarySearchIndex([1, 2, 3], 1)); 24 | 25 | // console.log(""); 26 | 27 | // console.log("Expecting: -1"); 28 | // console.log("=>", binarySearchIndex([4, 7, 20], 100)); 29 | } 30 | 31 | module.exports = { 32 | binarySearch, 33 | binarySearchIndex 34 | }; 35 | 36 | // Add a written explanation of your solution 37 | -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "binary_search", 3 | "version": "1.0.0", 4 | "description": "binary search", 5 | "main": "binary_search.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/phone_book.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/00-days-1-to-3--binary-search/phone_book.jpeg -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /10-week-8--searching/00-days-1-to-3--binary-search/ruby/binary_search.rb: -------------------------------------------------------------------------------- 1 | def binary_search(arr, target) 2 | # type your code in here 3 | end 4 | 5 | # BONUS: MODIFY YOUR CODE TO RETURN THE INDEX OF THE TARGET, -1 IF NOT FOUND 6 | def binary_search_index(arr, target) 7 | # type your code in here 8 | end 9 | 10 | if __FILE__ == $PROGRAM_NAME 11 | puts "Expecting: true" 12 | puts "=>", binary_search([1, 2, 3], 3) 13 | 14 | puts 15 | 16 | puts "Expecting: false" 17 | puts "=>", binary_search([3, 5, 9], 10) 18 | 19 | # Don't forget to add your own! 20 | 21 | # UNCOMMENT FOR BONUS 22 | # puts 23 | # puts "Expecting: 0" 24 | # puts "=>", binary_search_index([1, 2, 3], 1) 25 | 26 | # puts 27 | 28 | # puts "Expecting: -1" 29 | # puts "=>", binary_search_index([4, 7, 20], 100) 30 | end 31 | 32 | # Add a written explanation of your solution 33 | -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/invalid_trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/01-day-4--manual-binary-tree/invalid_trees.png -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/javascript/binary_tree.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor() { 3 | // add your Node class code 4 | } 5 | } 6 | 7 | // list = [1, 4, 7] 8 | function oneToSeven() { 9 | // manually create the BST 10 | // then return the root node 11 | } 12 | 13 | // list = [10, 40, 45, 46, 50] 14 | function tenToFifty() { 15 | 16 | } 17 | 18 | // list = [-20, -19, -17, -15, 0, 1, 2, 10] 19 | function negativeToPositive() { 20 | 21 | } 22 | 23 | if (require.main === module) { 24 | // add your own tests in here if you want 25 | } 26 | 27 | module.exports = { 28 | Node, 29 | oneToSeven, 30 | tenToFifty, 31 | negativeToPositive 32 | }; 33 | 34 | // Please add your pseudocode to this file 35 | // And a written explanation of your solution 36 | -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "binary_tree", 3 | "version": "1.0.0", 4 | "description": "binary tree", 5 | "main": "binary_tree.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/ruby/binary_tree.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :value, :left, :right 3 | 4 | def initialize() 5 | # add your Node class code 6 | end 7 | end 8 | 9 | # list = [1, 4, 7] 10 | def one_to_seven 11 | # manually create the BST 12 | # then return the root node 13 | end 14 | 15 | # list = [10, 40, 45, 46, 50] 16 | def ten_to_fifty 17 | 18 | end 19 | 20 | # list = [-20, -19, -17, -15, 0, 1, 2, 10] 21 | def negative_to_positive 22 | 23 | end 24 | 25 | if __FILE__ == $PROGRAM_NAME 26 | # Add your own tests if you want 27 | end 28 | 29 | # Please add your pseudocode to this file 30 | # And a written explanation of your solution 31 | -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/valid_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/01-day-4--manual-binary-tree/valid_tree.png -------------------------------------------------------------------------------- /10-week-8--searching/01-day-4--manual-binary-tree/valid_trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/01-day-4--manual-binary-tree/valid_trees.png -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/javascript/balancing.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(value, left = null, right = null) { 3 | this.value = value; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | // list = [3, 5, 6, 9, 10, 20] 10 | function threeToTwenty() { 11 | 12 | } 13 | 14 | // list = [10, 11, 30, 100, 200] 15 | function tenToTwoHundred() { 16 | 17 | } 18 | 19 | if (require.main === module) { 20 | // add tests in here if you need them 21 | } 22 | 23 | module.exports = { 24 | Node, 25 | threeToTwenty, 26 | tenToTwoHundred 27 | }; 28 | 29 | // Please add your pseudocode to this file 30 | // And a written explanation of your solution 31 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "balancing", 3 | "version": "1.0.0", 4 | "description": "balanced vs unbalanced trees", 5 | "main": "balancing.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/javascript/tests/balancing.test.js: -------------------------------------------------------------------------------- 1 | const { threeToTwenty, tenToTwoHundred } = require("../../solutions/balancing"); 2 | const { bstToArray, isBalanced } = require("./validation_methods"); 3 | 4 | describe("balanced BSTs", () => { 5 | describe("threeToTwenty", () => { 6 | test("returns the root node of a valid BST", () => { 7 | expect(bstToArray(threeToTwenty())).toStrictEqual([3, 5, 6, 9, 10, 20]); 8 | }); 9 | 10 | test("returns the root of a balanced BST", () => { 11 | expect(isBalanced(threeToTwenty())).toBe(true); 12 | }); 13 | }); 14 | 15 | describe("tenToTwoHundred", () => { 16 | test("returns the root node of a valid BST", () => { 17 | expect(bstToArray(tenToTwoHundred())).toStrictEqual([10, 11, 30, 100, 200]); 18 | }); 19 | 20 | test("returns the root of a balanced BST", () => { 21 | expect(isBalanced(tenToTwoHundred())).toBe(true); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/javascript/tests/validation_methods.js: -------------------------------------------------------------------------------- 1 | function bstToArray(root) { 2 | if (root === null) { 3 | return []; 4 | } 5 | 6 | const stack = [root]; 7 | const sorted = []; 8 | 9 | while (stack.length) { 10 | const node = stack[stack.length - 1]; 11 | 12 | if (node.left !== null) { 13 | stack.push(node.left); 14 | node.left = null; 15 | continue; 16 | } 17 | 18 | sorted.push(stack.pop().value); 19 | 20 | if (node.right !== null) { 21 | stack.push(node.right); 22 | } 23 | } 24 | 25 | return sorted; 26 | } 27 | 28 | function isBalanced(root) { 29 | if (root === null) { 30 | return true; 31 | } 32 | 33 | const leftHeight = branchHeight(root.left); 34 | const rightHeight = branchHeight(root.right); 35 | 36 | return Math.abs(leftHeight - rightHeight) < 2; 37 | } 38 | 39 | function branchHeight(root) { 40 | let queue = root === null ? [] : [root]; 41 | let count = 0; 42 | 43 | while(queue.length) { 44 | ++count; 45 | 46 | queue = queue.reduce((accum, node) => { 47 | if (node.left) { 48 | accum.push(node.left); 49 | } 50 | 51 | if (node.right) { 52 | accum.push(node.right); 53 | } 54 | 55 | return accum; 56 | }, []); 57 | } 58 | 59 | return count; 60 | } 61 | 62 | module.exports = { 63 | bstToArray, 64 | isBalanced 65 | }; -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/ruby/balancing.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :value, :left, :right 3 | 4 | def initialize(value, left = nil, right = nil) 5 | @value = value 6 | @left = left 7 | @right = right 8 | end 9 | end 10 | 11 | # list = [3, 5, 6, 9, 10, 20] 12 | def three_to_twenty 13 | 14 | end 15 | 16 | # list = [10, 11, 30, 100, 200] 17 | def ten_to_two_hundred 18 | 19 | end 20 | 21 | if __FILE__ == $PROGRAM_NAME 22 | # Add tests if you need them 23 | end 24 | 25 | # Please add your pseudocode to this file 26 | # And a written explanation of your solution 27 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/ruby/spec/balancing_spec.rb: -------------------------------------------------------------------------------- 1 | require "./balancing" 2 | require "./spec/validation_methods" 3 | 4 | RSpec.describe "balanced BSTs" do 5 | context "three_to_twenty" do 6 | it "returns the root node of a valid BST" do 7 | expect(Validator.bst_to_array(three_to_twenty)).to eq([3, 5, 6, 9, 10, 20]) 8 | end 9 | 10 | it "returns the root of a balanced BST" do 11 | expect(Validator.balanced?(three_to_twenty)).to be true 12 | end 13 | end 14 | 15 | context "ten_to_two_hundred" do 16 | it "returns the root node of a valid BST" do 17 | expect(Validator.bst_to_array(ten_to_two_hundred)).to eq([10, 11, 30, 100, 200]) 18 | end 19 | 20 | it "returns the root of a balanced BST" do 21 | expect(Validator.balanced?(ten_to_two_hundred)).to be true 22 | end 23 | end 24 | end -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/ruby/spec/validation_methods.rb: -------------------------------------------------------------------------------- 1 | class Validator 2 | def self.bst_to_array(root) 3 | if (root == nil) 4 | return [] 5 | end 6 | 7 | stack = [root] 8 | sorted = [] 9 | 10 | while stack.length > 0 11 | node = stack.last 12 | 13 | if (node.left != nil) 14 | stack.push(node.left) 15 | node.left = nil 16 | next 17 | end 18 | 19 | sorted.push(stack.pop().value) 20 | 21 | if (node.right != nil) 22 | stack.push(node.right) 23 | end 24 | end 25 | 26 | sorted 27 | end 28 | 29 | def self.balanced?(root) 30 | return true if root.nil? 31 | 32 | left_height = branch_height(root.left) 33 | right_height = branch_height(root.right) 34 | 35 | (left_height - right_height).abs < 2 36 | end 37 | 38 | def self.branch_height(root) 39 | queue = root.nil? ? [] : [root] 40 | count = 0 41 | 42 | until queue.empty? 43 | count += 1 44 | 45 | queue = queue.reduce([]) do |accum, node| 46 | accum << node.left if node.left 47 | accum << node.right if node.right 48 | accum 49 | end 50 | end 51 | 52 | count 53 | end 54 | end 55 | 56 | 57 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/solutions/balancing.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(value, left = null, right = null) { 3 | this.value = value; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | // list = [3, 5, 6, 9, 10, 20] 10 | // 6 11 | // 5 10 12 | // 3 9 20 13 | function threeToTwenty() { 14 | const three = new Node(3); 15 | const five = new Node(5, three); 16 | const nine = new Node(9); 17 | const twenty = new Node(20); 18 | const ten = new Node(10, nine, twenty); 19 | 20 | return new Node(6, five, ten); 21 | } 22 | 23 | // list = [10, 11, 30, 100, 200] 24 | // 30 25 | // 11 100 26 | // 10 200 27 | function tenToTwoHundred() { 28 | const ten = new Node(10); 29 | const eleven = new Node(11, ten); 30 | const two_hundred = new Node(200); 31 | const hundred = new Node(100, null, two_hundred); 32 | 33 | return new Node(30, eleven, hundred); 34 | } 35 | 36 | if (require.main === module) { 37 | // add tests in here if you need them 38 | } 39 | 40 | module.exports = { 41 | Node, 42 | threeToTwenty, 43 | tenToTwoHundred 44 | }; 45 | 46 | // Please add your pseudocode to this file 47 | // And a written explanation of your solution 48 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/solutions/balancing.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :value, :left, :right 3 | 4 | def initialize(value, left = nil, right = nil) 5 | @value = value 6 | @left = left 7 | @right = right 8 | end 9 | end 10 | 11 | # list = [3, 5, 6, 9, 10, 20] 12 | # 6 13 | # 5 10 14 | # 3 9 20 15 | def three_to_twenty 16 | three = Node.new(3) 17 | five = Node.new(5, three) 18 | nine = Node.new(9) 19 | twenty = Node.new(20) 20 | ten = Node.new(10, nine, twenty) 21 | 22 | Node.new(6, five, ten) 23 | end 24 | 25 | # list = [10, 11, 30, 100, 200] 26 | # 30 27 | # 11 100 28 | # 10 200 29 | def ten_to_two_hundred 30 | ten = Node.new(10) 31 | eleven = Node.new(11, ten) 32 | two_hundred = Node.new(200) 33 | hundred = Node.new(100, nil, two_hundred) 34 | 35 | Node.new(30, eleven, hundred) 36 | end 37 | 38 | if __FILE__ == $PROGRAM_NAME 39 | # Add tests if you need them 40 | end 41 | 42 | # Please add your pseudocode to this file 43 | # And a written explanation of your solution 44 | -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/tree_compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/02-day-5--build-a-binary-tree---balancing/tree_compare.png -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/tree_height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/02-day-5--build-a-binary-tree---balancing/tree_height.png -------------------------------------------------------------------------------- /10-week-8--searching/02-day-5--build-a-binary-tree---balancing/valid_trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/10-week-8--searching/02-day-5--build-a-binary-tree---balancing/valid_trees.png -------------------------------------------------------------------------------- /11-pairing-exercise-3/00-pair-programming/README.md: -------------------------------------------------------------------------------- 1 | # Pair Programming 2 | 3 | ## Introduction 4 | 5 | For this activity, you will pair up and complete a challenge from the previous 6 | exercises pair-programming style! In other words, one of you will be the driver 7 | and the other will be the navigator, and then you will switch. Remember to be 8 | patient with one another and to keep the lines of communication open. If one of 9 | you becomes quiet for an extended period of time, ask a question to help keep 10 | things moving. 11 | 12 | ## Instructions 13 | 14 | - Choose a problem from the previous exercises that you were unable to solve, 15 | have not tried yet, or struggled with a lot 16 | - If you are the navigator, you will guide the driver by doing the following: 17 | - Communicate in simple and small steps what code should be written 18 | - Explain why you're making those decisions 19 | - Inform the driver when they're misunderstanding your directions or are making syntactical errors 20 | - Point out any improvements that can be made to the code 21 | - If time allows and problem has been solved, guide the driver through a refactor to improve the code 22 | - If you are the driver, you will write code according to the navigator's instructions: 23 | - Ask questions when you don't understand the what or the why 24 | - If you disagree with a decision, diplomatically state your disagreement and why 25 | - Be the typist 26 | - Stay focused on the current task 27 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "level_order_tree_traversal", 3 | "version": "1.0.0", 4 | "description": "level order tree traversal", 5 | "main": "tree_traversal_bfs.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/javascript/tree_traversal_bfs.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(value, left = null, right = null) { 3 | this.value = value; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | function levelOrderTraversal(root) { 10 | // type your code here 11 | } 12 | 13 | if (require.main === module) { 14 | let root = new Node(1, new Node(2), new Node(3)); 15 | // add your own tests in here 16 | console.log("Expecting: [[1], [2, 3]]"); 17 | console.log(levelOrderTraversal(root)); 18 | 19 | console.log(""); 20 | 21 | root = new Node(10, new Node(20, new Node(9), new Node(22)), new Node(30)); 22 | 23 | console.log("Expecting: [[10], [20, 30], [9, 22]]"); 24 | console.log(levelOrderTraversal(root)); 25 | } 26 | 27 | module.exports = { 28 | Node, 29 | levelOrderTraversal 30 | }; 31 | 32 | // Please add your pseudocode to this file 33 | // And a written explanation of your solution 34 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/ruby/tree_traversal_bfs.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :value, :left, :right 3 | 4 | def initialize(value, left = nil, right = nil) 5 | @value = value 6 | @left = left 7 | @right = right 8 | end 9 | end 10 | 11 | def level_order_traversal(root) 12 | # type your code in here 13 | end 14 | 15 | if __FILE__ == $PROGRAM_NAME 16 | root = Node.new(1, Node.new(2), Node.new(3)); 17 | 18 | puts "Expecting: [[1], [2, 3]]" 19 | print level_order_traversal(root) 20 | 21 | puts 22 | puts 23 | 24 | root = Node.new(10, Node.new(20, Node.new(9), Node.new(22)), Node.new(30)) 25 | 26 | puts "Expecting: [[10], [20, 30], [9, 22]]" 27 | print level_order_traversal(root) 28 | 29 | puts 30 | puts 31 | 32 | # Don't forget to add your own! 33 | end 34 | 35 | # Please add your pseudocode to this file 36 | # And a written explanation of your solution 37 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/trees.png -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/unordered_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/12-week-9--searching-and-sorting-continued/00-days-1-to-2--binary-tree-traversal--level-order---breadth-first/unordered_tree.png -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inorder_traversal", 3 | "version": "1.0.0", 4 | "description": "in order traversal", 5 | "main": "tree_traversal_inorder.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/javascript/tree_traversal_inorder.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(value, left = null, right = null) { 3 | this.value = value; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | function treeTraversalInorder(root) { 10 | // type your code here 11 | } 12 | 13 | if (require.main === module) { 14 | // add your own tests in here 15 | let root = new Node(2, new Node(-10), new Node(20)); 16 | console.log("Expecting: [-10, 2, 20]"); 17 | console.log(treeTraversalInorder(root)); 18 | 19 | console.log(""); 20 | 21 | root = new Node(10, new Node(0, null, new Node(5)), new Node(20, null, new Node(30))); 22 | console.log("Expecting: [0, 5, 10, 20, 30] "); 23 | console.log(treeTraversalInorder(root)); 24 | } 25 | 26 | module.exports = { 27 | Node, 28 | treeTraversalInorder 29 | }; 30 | 31 | // Please add your pseudocode to this file 32 | // And a written explanation of your solution 33 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/ruby/tree_traversal_inorder.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :value, :left, :right 3 | 4 | def initialize(value, left = nil, right = nil) 5 | @value = value 6 | @left = left 7 | @right = right 8 | end 9 | end 10 | 11 | def tree_traversal_inorder(root) 12 | # type your code in here 13 | end 14 | 15 | if __FILE__ == $PROGRAM_NAME 16 | root = Node.new(2, Node.new(-10), Node.new(20)) 17 | puts "Expecting: [-10, 2, 20]" 18 | print tree_traversal_inorder(root) 19 | puts 20 | 21 | puts 22 | 23 | root = Node.new(10, Node.new(0, nil, Node.new(5)), Node.new(20, nil, Node.new(30))) 24 | puts "Expecting: [0, 5, 10, 20, 30] " 25 | print tree_traversal_inorder(root) 26 | puts 27 | 28 | # Don't forget to add your own! 29 | end 30 | 31 | # Please add your pseudocode to this file 32 | # And a written explanation of your solution 33 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/trees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/12-week-9--searching-and-sorting-continued/01-day-3-to-4--tree-traversal-in-order/trees.png -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/javascript/find_target.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(value, left = null, right = null) { 3 | this.value = value; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | function findTarget(root, target) { 10 | // type your code here 11 | } 12 | 13 | if (require.main === module) { 14 | // add your own tests in here 15 | const root = new Node(1, new Node(-1), new Node(2)); 16 | console.log("Expecting: Node with value 2"); 17 | console.log(findTarget(root, 2)); 18 | 19 | console.log(""); 20 | 21 | console.log("Expecting: null"); 22 | console.log(findTarget(root, 5)); 23 | } 24 | 25 | module.exports = { findTarget, Node }; 26 | 27 | // Please add your pseudocode to this file 28 | // And a written explanation of your solution 29 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "find_target", 3 | "version": "1.0.0", 4 | "description": "find target node in BST", 5 | "main": "find_target.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/ruby/find_target.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :value, :left, :right 3 | 4 | def initialize(value, left = nil, right = nil) 5 | @value = value 6 | @left = left 7 | @right = right 8 | end 9 | end 10 | 11 | def find_target(root, target) 12 | # type your code in here 13 | end 14 | 15 | if __FILE__ == $PROGRAM_NAME 16 | root = Node.new(1, Node.new(-1), Node.new(2)) 17 | puts "Expecting: Node with value 2" 18 | puts find_target(root, 2).inspect 19 | 20 | puts 21 | 22 | puts "Expecting: nil" 23 | puts find_target(root, 5).inspect 24 | 25 | # Don't forget to add your own! 26 | end 27 | 28 | # Please add your pseudocode to this file 29 | # And a written explanation of your solution 30 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/02-day-5--find-value-binary-tree/ruby/spec/find_target_spec.rb: -------------------------------------------------------------------------------- 1 | require "./find_target" 2 | 3 | RSpec.describe "find_target" do 4 | it "can handle an empty tree" do 5 | expect(find_target(nil, 5)).to be nil 6 | end 7 | 8 | it "can handle a tree with only a root node" do 9 | root = Node.new(5) 10 | 11 | expect(find_target(root, 5)).to be(root) 12 | expect(find_target(root, 7)).to be nil 13 | end 14 | 15 | it "can find the target node in a small balanced tree" do 16 | root = Node.new(1, Node.new(-1), Node.new(2)) 17 | 18 | expect(find_target(root, 2)).to be root.right 19 | end 20 | 21 | it "returns the correct result for unbalanced trees" do 22 | root = Node.new(10, Node.new(9, Node.new(8, Node.new(7)))) 23 | root_two = Node.new(1, nil, Node.new(2, nil, Node.new(3, nil, Node.new(4, nil, Node.new(5))))) 24 | 25 | expect(find_target(root, 8)).to be root.left.left 26 | expect(find_target(root_two, 5)).to be root_two.right.right.right.right 27 | end 28 | 29 | it "returns the correct result for a larger tree" do 30 | root = Node.new(10, Node.new(7, Node.new(6, Node.new(4)), Node.new(8)), Node.new(14, Node.new(11), Node.new(18, nil, Node.new(20)))) 31 | 32 | expect(find_target(root, 20)).to be root.right.right.right 33 | expect(find_target(root, 5)).to be nil 34 | end 35 | end -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "quicksort", 3 | "version": "1.0.0", 4 | "description": "quicksort", 5 | "main": "quicksort.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/javascript/quicksort.js: -------------------------------------------------------------------------------- 1 | function partition(array, low, high) { 2 | // type your code in here 3 | } 4 | 5 | function quicksort(array, low = 0, high = array.length - 1) { 6 | // type your code here 7 | } 8 | 9 | if (require.main === module) { 10 | // add your own tests in here 11 | console.log("Expecting: [1, 2, 3, 4]"); 12 | console.log(quicksort([3, 2, 1, 4])); 13 | 14 | console.log(""); 15 | 16 | console.log("Expecting: [1, 2, 2, 3, 4]"); 17 | console.log(quicksort([1, 2, 2, 3, 4])); 18 | } 19 | 20 | module.exports = quicksort; 21 | 22 | // Please add your pseudocode to this file 23 | // And a written explanation of your solution 24 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/quick_sort_partition_animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/12-week-9--searching-and-sorting-continued/03-bonus--quicksort/quick_sort_partition_animation.gif -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/quicksort_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/12-week-9--searching-and-sorting-continued/03-bonus--quicksort/quicksort_diagram.png -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /12-week-9--searching-and-sorting-continued/03-bonus--quicksort/ruby/quicksort.rb: -------------------------------------------------------------------------------- 1 | def partition(array, low, high) 2 | # type your code in here 3 | end 4 | 5 | def quicksort(array, low = 0, high = array.length - 1) 6 | # type your code in here 7 | end 8 | 9 | if __FILE__ == $PROGRAM_NAME 10 | puts "Expecting: [1, 2, 3, 4]" 11 | print quicksort([3, 2, 1, 4]) 12 | puts 13 | 14 | puts 15 | 16 | puts "Expecting: [1, 2, 2, 3, 4]" 17 | print quicksort([1, 2, 2, 3, 4]) 18 | puts 19 | 20 | # Don't forget to add your own! 21 | end 22 | 23 | # Please add your pseudocode to this file 24 | # And a written explanation of your solution 25 | -------------------------------------------------------------------------------- /13-week-10/00-days-1-to-2--create-a-queue-class-using-nodes/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /13-week-10/00-days-1-to-2--create-a-queue-class-using-nodes/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "queue", 3 | "version": "1.0.0", 4 | "description": "build a queue class", 5 | "main": "queue.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /13-week-10/00-days-1-to-2--create-a-queue-class-using-nodes/javascript/queue.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(data = null, next = null) { 3 | this.data = data; 4 | this.next = next; 5 | } 6 | } 7 | 8 | class Queue { 9 | constructor(front = null) { 10 | this.front = front; 11 | this.rear = front; 12 | } 13 | 14 | // ADD NODE TO BACK OF QUEUE 15 | // USE DATA TO CREATE A NEW NODE AND ADD IT TO THE QUEUE 16 | enqueue(data) { 17 | 18 | } 19 | 20 | // REMOVE NODE FROM FRONT OF QUEUE AND RETURN IT 21 | dequeue() { 22 | 23 | } 24 | 25 | // RETURN NODE AT FRONT WITHOUT REMOVING IT 26 | peek() { 27 | 28 | } 29 | 30 | // RETURN TRUE IF QUEUE IS EMPTY, OTHERWISE FALSE 31 | isEmpty() { 32 | 33 | } 34 | 35 | // RETURN NUMBER OF NODES IN QUEUE, E.G. 10 36 | size() { 37 | 38 | } 39 | 40 | // RETURN INTEGER REPRESENTING HOW FAR TARGET IS FROM FRONT OF QUEUE 41 | // IF TARGET ISN'T IN QUEUE, RETURN -1 42 | search(target) { 43 | 44 | } 45 | } 46 | 47 | if (require.main === module) { 48 | // add your own tests in here 49 | 50 | } 51 | 52 | module.exports = { 53 | Node, 54 | Queue 55 | }; 56 | 57 | // Write your Big O findings here 58 | 59 | // Optional: Please add your pseudocode to this file 60 | // Optional: And a written explanation of your solution 61 | -------------------------------------------------------------------------------- /13-week-10/00-days-1-to-2--create-a-queue-class-using-nodes/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /13-week-10/00-days-1-to-2--create-a-queue-class-using-nodes/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /13-week-10/00-days-1-to-2--create-a-queue-class-using-nodes/ruby/queue.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :data, :next_node 3 | 4 | def initialize(data = nil, next_node = nil) 5 | @data = data 6 | @next_node = next_node 7 | end 8 | end 9 | 10 | class Queue 11 | attr_reader :front, :rear 12 | 13 | def initialize(front = nil) 14 | @front = front 15 | @rear = front 16 | end 17 | 18 | # ADD NODE TO BACK OF QUEUE 19 | # USE DATA TO CREATE A NEW NODE AND ADD IT TO THE QUEUE 20 | def enqueue(data) 21 | 22 | end 23 | 24 | # REMOVE NODE FROM FRONT OF QUEUE AND RETURN IT 25 | def dequeue 26 | 27 | end 28 | 29 | # RETURN NODE AT FRONT WITHOUT REMOVING IT 30 | def peek 31 | 32 | end 33 | 34 | # RETURN TRUE IF QUEUE IS EMPTY, OTHERWISE FALSE 35 | def isEmpty 36 | 37 | end 38 | 39 | # RETURN NUMBER OF NODES IN QUEUE, E.G. 10 40 | def size 41 | 42 | end 43 | 44 | # RETURN INTEGER REPRESENTING HOW FAR TARGET IS FROM FRONT OF QUEUE 45 | # IF TARGET ISN'T IN QUEUE, RETURN -1 46 | def search(target) 47 | 48 | end 49 | end 50 | 51 | if __FILE__ == $PROGRAM_NAME 52 | # Add your own tests in here 53 | end 54 | 55 | # Write your Big O findings here 56 | 57 | # Optional: Please add your pseudocode to this file 58 | # Optional: And a written explanation of your solution 59 | -------------------------------------------------------------------------------- /13-week-10/01-days-3-to-5--build-an-lru-cache/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /13-week-10/01-days-3-to-5--build-an-lru-cache/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lru-cache", 3 | "version": "1.0.0", 4 | "description": "LRU Cache", 5 | "main": "lru_cache.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /13-week-10/01-days-3-to-5--build-an-lru-cache/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /13-week-10/01-days-3-to-5--build-an-lru-cache/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/friends.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/14-week-11/00-day-1--what-is-a-graph-/friends.jpg -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/javascript/graph.js: -------------------------------------------------------------------------------- 1 | class Graph { 2 | constructor(paths) { 3 | 4 | } 5 | 6 | isAdjacent(vertexA, vertexB) { 7 | 8 | } 9 | 10 | // array is an adjacency list 11 | addVertex(vertex, array) { 12 | 13 | } 14 | } 15 | 16 | if (require.main === module) { 17 | // add your own tests in here 18 | let graph = new Graph([]); 19 | 20 | console.log("Expecting: {}"); 21 | console.log(graph.graph); 22 | 23 | console.log(""); 24 | 25 | graph = new Graph([["a", "b", "c"], ["b", "d"]]); 26 | 27 | console.log('Expecting: { a: { "b" }, b: { "a", "c", "d" }, c: { "b" }, d: { "b" }}'); 28 | console.log(graph.graph); 29 | 30 | console.log(""); 31 | 32 | console.log("Expecting: true"); 33 | console.log(graph.isAdjacent("a", "b")); 34 | 35 | console.log(""); 36 | 37 | console.log("Expecting: false"); 38 | console.log(graph.isAdjacent("a", "c")); 39 | 40 | console.log(""); 41 | 42 | graph.addVertex("e", ["a", "d"]); 43 | console.log('Expecting: { a: { "b", "e" }, b: { "a", "c", "d" }, c: { "b" }, d: { "b", "e" }, e: { "a", "d" } }'); 44 | console.log(graph.graph); 45 | 46 | console.log("") 47 | } 48 | 49 | module.exports = Graph; 50 | 51 | // Please add your pseudocode to this file 52 | // And a written explanation of your solution 53 | -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graph", 3 | "version": "1.0.0", 4 | "description": "graph", 5 | "main": "graph.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /14-week-11/00-day-1--what-is-a-graph-/ruby/graph.rb: -------------------------------------------------------------------------------- 1 | require 'set' 2 | 3 | class Graph 4 | def initialize(paths) 5 | end 6 | 7 | def is_adjacent(vertex_a, vertex_b) 8 | end 9 | 10 | # array is an adjacency list 11 | def add_vertex(vertex, array) 12 | end 13 | end 14 | 15 | if __FILE__ == $PROGRAM_NAME 16 | graph = Graph.new([]) 17 | 18 | puts "Expecting: {}" 19 | puts graph.graph 20 | 21 | puts 22 | 23 | graph = Graph.new([["a", "b", "c"], ["b", "d"]]) 24 | 25 | puts 'Expecting: { a: { "b" }, b: { "a", "c", "d" }, c: { "b" }, d: { "b" }}' 26 | puts graph.graph 27 | 28 | puts 29 | 30 | # Don't forget to add your own! 31 | 32 | puts "Expecting: true" 33 | puts graph.is_adjacent("a", "b") 34 | 35 | puts 36 | 37 | puts "Expecting: false" 38 | puts graph.is_adjacent("a", "c") 39 | 40 | puts 41 | 42 | graph.add_vertex("e", ["a", "d"]) 43 | puts 'Expecting: { a: { "b", "e" }, b: { "a", "c", "d" }, c: { "b" }, d: { "b", "e" }, e: { "a", "d" } }' 44 | puts graph.graph 45 | end 46 | 47 | # Please add your pseudocode to this file 48 | # And a written explanation of your solution 49 | -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/fork_road.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/14-week-11/01-days-2-to-3--depth-first-graph-traversal/fork_road.jpg -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/graph.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/14-week-11/01-days-2-to-3--depth-first-graph-traversal/graph.jpg -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/javascript/graph_dfs.js: -------------------------------------------------------------------------------- 1 | function isPath(graph, vertexA, vertexB) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | let graph = { 8 | jan: ["john", "jambaby"], 9 | john: ["carl"], 10 | jambaby: [], 11 | carl: ["jambaby"], 12 | dave: [] 13 | }; 14 | 15 | console.log("Expecting: true"); 16 | console.log(isPath(graph, "jan", "carl")); 17 | 18 | console.log(""); 19 | 20 | console.log("Expecting: false"); 21 | console.log(isPath(graph, "jan", "dave")); 22 | } 23 | 24 | module.exports = isPath; 25 | 26 | // Please add your pseudocode to this file 27 | // And a written explanation of your solution 28 | -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graph_dfs", 3 | "version": "1.0.0", 4 | "description": "depth-first graph traversal", 5 | "main": "graph_dfs.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /14-week-11/01-days-2-to-3--depth-first-graph-traversal/ruby/graph_dfs.rb: -------------------------------------------------------------------------------- 1 | def is_path(graph, vertex_a, vertex_b) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | graph = { 7 | jan: [:john, :jambaby], 8 | john: [:carl], 9 | jambaby: [], 10 | carl: [:jambaby], 11 | dave: [] 12 | } 13 | 14 | puts "Expecting: true" 15 | puts is_path(graph, :jan, :carl) 16 | 17 | puts 18 | 19 | puts "Expecting: false" 20 | puts is_path(graph, :jan, :dave) 21 | 22 | # Don't forget to add your own! 23 | end 24 | 25 | # Please add your pseudocode to this file 26 | # And a written explanation of your solution 27 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/graph.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/14-week-11/02-days-4-to-5--breadth-first-graph-traversal/graph.jpg -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/javascript/find_distance.js: -------------------------------------------------------------------------------- 1 | function findDistance(graph, vertexA, vertexB) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | const graph = { 8 | jan: ["john", "jambaby"], 9 | john: ["carl"], 10 | jambaby: [], 11 | carl: ["jambaby"], 12 | dave: [] 13 | }; 14 | 15 | console.log("Expecting: 2"); 16 | console.log(findDistance(graph, "jan", "carl")); 17 | 18 | console.log(""); 19 | 20 | console.log("Expecting: -1"); 21 | console.log(findDistance(graph, "dave", "carl")); 22 | } 23 | 24 | module.exports = findDistance; 25 | 26 | // Please add your pseudocode to this file 27 | // And a written explanation of your solution 28 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "find_distance", 3 | "version": "1.0.0", 4 | "description": "find shortest distance between vertices", 5 | "main": "find_distance.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/javascript/tests/find_distance.test.js: -------------------------------------------------------------------------------- 1 | const findDistance = require("../find_distance"); 2 | 3 | describe("findDistance", () => { 4 | const graphSmall = { 5 | jan: ["john", "jambaby"], 6 | john: ["carl"], 7 | jambaby: [], 8 | carl: ["jambaby"], 9 | dave: [] 10 | }; 11 | 12 | const graphMed = { 13 | jan: ["cranberry", "jamboree"], 14 | john: ["jambaby"], 15 | jambaby: ["jan", "cranberry"], 16 | carl: [], 17 | dave: ["john", "carl"], 18 | cranberry: [], 19 | hamtaro: ["jambaby", "dave"], 20 | jamboree: ["carl", "john"] 21 | }; 22 | 23 | it("returns the shortest distance between two vertices when there's a path between them", () => { 24 | expect(findDistance(graphSmall, "jan", "carl")).toEqual(2); 25 | expect(findDistance(graphMed, "dave", "carl")).toEqual(1); 26 | }); 27 | 28 | it("returns -1 when there is no path between vertices", () => { 29 | expect(findDistance(graphSmall, "dave", "carl")).toEqual(-1); 30 | expect(findDistance(graphSmall, "jambaby", "carl")).toEqual(-1); 31 | expect(findDistance(graphMed, "jamboree", "hamtaro")).toEqual(-1); 32 | }); 33 | 34 | it("returns the correct distance when detecting cycles", () => { 35 | expect(findDistance(graphSmall, "jan", "jan")).toEqual(-1); 36 | expect(findDistance(graphMed, "jan", "jan")).toEqual(4); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/ruby/find_distance.rb: -------------------------------------------------------------------------------- 1 | def find_distance(graph, vertex_a, vertex_b) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | graph = { 7 | jan: [:john, :jambaby], 8 | john: [:carl], 9 | jambaby: [], 10 | carl: [:jambaby], 11 | dave: [] 12 | } 13 | 14 | puts "Expecting: 2" 15 | puts find_distance(graph, :jan, :carl) 16 | 17 | puts 18 | 19 | puts "Expecting: -1" 20 | puts find_distance(graph, :dave, :carl) 21 | 22 | # Don't forget to add your own! 23 | end 24 | 25 | # Please add your pseudocode to this file 26 | # And a written explanation of your solution 27 | -------------------------------------------------------------------------------- /14-week-11/02-days-4-to-5--breadth-first-graph-traversal/ruby/spec/find_distance_spec.rb: -------------------------------------------------------------------------------- 1 | require "./find_distance" 2 | 3 | RSpec.describe "find_distance" do 4 | graph_small = { 5 | jan: [:john, :jambaby], 6 | john: [:carl], 7 | jambaby: [], 8 | carl: [:jambaby], 9 | dave: [] 10 | } 11 | 12 | graph_med = { 13 | jan: [:cranberry, :jamboree], 14 | john: [:jambaby], 15 | jambaby: [:jan, :cranberry], 16 | carl: [], 17 | dave: [:john, :carl], 18 | cranberry: [], 19 | hamtaro: [:jambaby, :dave], 20 | jamboree: [:carl, :john] 21 | } 22 | 23 | it "returns the shortest distance between two vertices when there's a path between them" do 24 | expect(find_distance(graph_small, :jan, :carl)).to eq 2 25 | expect(find_distance(graph_med, :dave, :carl)).to eq 1 26 | end 27 | 28 | it "returns -1 when there is no path between vertices" do 29 | expect(find_distance(graph_small, :dave, :carl)).to eq -1 30 | expect(find_distance(graph_small, :jambaby, :carl)).to eq -1 31 | expect(find_distance(graph_med, :jamboree, :hamtaro)).to eq -1 32 | end 33 | 34 | it "returns the correct distance when detecting cycles" do 35 | expect(find_distance(graph_small, :jan, :jan)).to eq -1 36 | expect(find_distance(graph_med, :jan, :jan)).to eq 4 37 | end 38 | end -------------------------------------------------------------------------------- /15-week-12/00-days-1-to-2--convert-html-to-a-graph/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /15-week-12/00-days-1-to-2--convert-html-to-a-graph/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "table-to-graph", 3 | "version": "1.0.0", 4 | "description": "convert html table to a graph", 5 | "main": "table_to_graph.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /15-week-12/00-days-1-to-2--convert-html-to-a-graph/javascript/table_to_graph.js: -------------------------------------------------------------------------------- 1 | function tableToGraph(friends) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | function printResults(obj) { 7 | for (const key in obj) { 8 | console.log(`${key}: ${obj[key]}`); 9 | } 10 | } 11 | 12 | // add your own tests in here 13 | const friends = "
PersonFriends
FredJane, Carol, Anesh, Xi
CarolFred, Anesh, Janelle
"; 14 | const result = { 15 | Fred: ["Jane", "Carol", "Anesh", "Xi"], 16 | Jane: ["Fred"], 17 | Carol: ["Fred", "Anesh", "Janelle"], 18 | Anesh: ["Fred", "Carol"], 19 | Xi: ["Fred"], 20 | Janelle: ["Carol"] 21 | }; 22 | 23 | console.log("Expecting: "); 24 | console.log(printResults(result)); 25 | console.log(""); 26 | console.log("Got: "); 27 | console.log(printResults(tableToGraph(friends))); 28 | 29 | console.log(""); 30 | } 31 | 32 | module.exports = tableToGraph; 33 | 34 | // Please add your pseudocode to this file 35 | // And a written explanation of your solution 36 | -------------------------------------------------------------------------------- /15-week-12/00-days-1-to-2--convert-html-to-a-graph/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' 8 | -------------------------------------------------------------------------------- /15-week-12/00-days-1-to-2--convert-html-to-a-graph/ruby/table_to_graph.rb: -------------------------------------------------------------------------------- 1 | def table_to_graph(friends) 2 | # type your code in here 3 | end 4 | 5 | if __FILE__ == $PROGRAM_NAME 6 | def print_results(hash) 7 | hash.each { |key, val| puts "#{key}: #{val}" } 8 | end 9 | 10 | friends = "
PersonFriends
FredJane, Carol, Anesh, Xi
CarolFred, Anesh, Janelle
" 11 | result = { 12 | "Fred" => ["Jane", "Carol", "Anesh", "Xi"], 13 | "Jane" => ["Fred"], 14 | "Carol" => ["Fred", "Anesh", "Janelle"], 15 | "Anesh" => ["Fred", "Carol"], 16 | "Xi" => ["Fred"], 17 | "Janelle" => ["Carol"] 18 | } 19 | 20 | puts "Expecting: " 21 | print_results(result) 22 | puts 23 | puts "Got: " 24 | print_results(table_to_graph(friends)) 25 | 26 | puts 27 | 28 | # Don't forget to add your own! 29 | end 30 | 31 | # Please add your pseudocode to this file 32 | # And a written explanation of your solution 33 | -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/javascript/fibonacci.js: -------------------------------------------------------------------------------- 1 | function fibonacci(num) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | // add your own tests in here 7 | console.log("Expecting: 0"); 8 | console.log("=>", fibonacci(0)); 9 | 10 | console.log(""); 11 | 12 | console.log("Expecting: 1"); 13 | console.log("=>", fibonacci(2)); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 55"); 18 | console.log("=>", fibonacci(10)); 19 | } 20 | 21 | module.exports = fibonacci; 22 | 23 | // Please add your pseudocode to this file 24 | // And a written explanation of your solution -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fibonacci", 3 | "version": "1.0.0", 4 | "description": "find nth value in fibo sequence with DP", 5 | "main": "fibonacci.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/javascript/tests/fibonacci.test.js: -------------------------------------------------------------------------------- 1 | const fibonacci = require('../fibonacci'); 2 | 3 | const fibo = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811]; 4 | 5 | for (let i = 0; i < 10; ++i) { 6 | test(`outputs the correct number in the sequence at index ${i}`, () => { 7 | expect(fibonacci(i)).toBe(fibo[i]); 8 | }); 9 | } 10 | 11 | test('outputs the correct number in the sequence at index 28', () => { 12 | expect(fibonacci(28)).toBe(fibo[28]); 13 | }); -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/ruby/fibonacci.rb: -------------------------------------------------------------------------------- 1 | 2 | def fibonacci(num) 3 | # type your code here 4 | end 5 | 6 | if __FILE__ == $PROGRAM_NAME 7 | puts "Expecting: 0" 8 | puts "=>", fibonacci(0) 9 | 10 | puts 11 | 12 | puts "Expecting: 1" 13 | puts "=>", fibonacci(2) 14 | 15 | puts 16 | 17 | puts "Expecting: 55" 18 | puts "=>", fibonacci(10) 19 | 20 | # Don't forget to add your own! 21 | end 22 | 23 | # Please add your pseudocode to this file 24 | # And a written explanation of your solution -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/ruby/spec/fibonacci_spec.rb: -------------------------------------------------------------------------------- 1 | require './fibonacci' 2 | 3 | RSpec.describe '#fibonacci' do 4 | fibo = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811] 5 | 6 | 10.times do |n| 7 | it "outputs the correct number in the sequence at index #{n}" do 8 | expect(fibonacci(n)).to eq(fibo[n]) 9 | end 10 | end 11 | 12 | it "outputs the correct number at index 28" do 13 | expect(fibonacci(28)).to eq(fibo[28]) 14 | end 15 | end -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/solutions/fibonacci.js: -------------------------------------------------------------------------------- 1 | let fibs = []; 2 | 3 | function fibonacci(num) { 4 | if (num === 0 || num === 1) return num 5 | if (fibs[num]) return fibs[num] 6 | fibs[num] = fibonacci(num - 1) + fibonacci(num - 2) 7 | return fibs[num] 8 | } 9 | 10 | if (require.main === module) { 11 | // add your own tests in here 12 | console.log("Expecting: 0"); 13 | console.log("=>", fibonacci(0)); 14 | 15 | console.log(""); 16 | 17 | console.log("Expecting: 1"); 18 | console.log("=>", fibonacci(2)); 19 | 20 | console.log(""); 21 | 22 | console.log("Expecting: 55"); 23 | console.log("=>", fibonacci(10)); 24 | } 25 | 26 | module.exports = fibonacci; 27 | 28 | // Please add your pseudocode to this file 29 | 30 | // fib(4) = fib(3) + fib(2) 31 | // fib(2), fib(3) were already saved into mem, so will fib(4) 32 | 33 | // fib(5) = fib(4) + fib(3) 34 | // The previously saved fib(3) and fib(4) will be used to avoid duplicated calculation and call stacks 35 | 36 | // And a written explanation of your solution 37 | 38 | // In a nutshell, DP is a efficient way in which we can use memoziation to cache visited data to faster retrieval later on. 39 | 40 | // This implementation makes use of mem as an array (or hash) to store value of an already computed num. This will greatly reduce the number of call stack and duplicated computation in the call stack. 41 | 42 | // Time complexity O(N), Space O(N) 43 | 44 | -------------------------------------------------------------------------------- /17-week-13/00-day-1-to-2--dynamic-programming/solutions/fibonacci.rb: -------------------------------------------------------------------------------- 1 | Fibs = {} 2 | 3 | def fibonacci(num) 4 | return num if num == 0 || num == 1 5 | return Fibs[num] if Fibs.keys.include?(num) 6 | 7 | Fibs[num] = fibonacci(num -1) + fibonacci(num - 2) 8 | return Fibs[num] 9 | end 10 | 11 | if __FILE__ == $PROGRAM_NAME 12 | puts "Expecting: 0" 13 | puts "=>", fibonacci(0) 14 | 15 | puts 16 | 17 | puts "Expecting: 1" 18 | puts "=>", fibonacci(2) 19 | 20 | puts 21 | 22 | puts "Expecting: 55" 23 | puts "=>", fibonacci(10) 24 | 25 | # Don't forget to add your own! 26 | end 27 | 28 | # // Please add your pseudocode to this file 29 | 30 | # // fib(4) = fib(3) + fib(2) 31 | # // fib(2), fib(3) were already saved into mem, so will fib(4) 32 | 33 | # // fib(5) = fib(4) + fib(3) 34 | # // The previously saved fib(3) and fib(4) will be used to avoid duplicated calculation and call stacks 35 | 36 | # // And a written explanation of your solution 37 | 38 | # // In a nutshell, DP is a efficient way in which we can use memoziation to cache visited data to faster retrieval later on. 39 | 40 | # // This implementation makes use of mem as an array (or hash) to store value of an already computed num. This will greatly reduce the number of call stack and duplicated computation in the call stack. 41 | 42 | # // Time complexity O(N), Space O(N) -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/example.png -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/javascript/addTwoList.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(val = null, next = null) { 3 | this.val = val; 4 | this.next = next; 5 | } 6 | } 7 | 8 | function addTwoList(l1, l2) { 9 | // type your code here 10 | } 11 | 12 | if (require.main === module) { 13 | // add your own tests in here 14 | console.log("Expecting: { val: 0, next: null }"); 15 | console.log("=>", addTwoNumbers({ val: 0, next: null }, { val: 0, next: null })); 16 | 17 | } 18 | 19 | module.exports = { 20 | Node, 21 | addTwoList 22 | }; 23 | 24 | // Please add your pseudocode to this file 25 | // And a written explanation of your solution -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "addtwolist", 3 | "version": "1.0.0", 4 | "description": "Add Two Numbers (List Nodes)", 5 | "main": "addTwoList.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/javascript/tests/addTwoList.test.js: -------------------------------------------------------------------------------- 1 | const { Node , addTwoList } = require('../addTwoList'); 2 | 3 | const n1 = new Node(3) 4 | const n2 = new Node(4, n1) 5 | const l1 = new Node(2, n2) 6 | 7 | const n3 = new Node(4) 8 | const n4 = new Node(6, n3) 9 | const l2 = new Node(5, n4) 10 | 11 | test('Input: l1 = [2,4,3] & l2 = [5,6,4], Output: [7,0,8]', () => { 12 | expect(addTwoList(l1,l2)).toEqual({"next": {"next": {"next": null, "val": 8}, "val": 0}, "val": 7}); 13 | }); 14 | 15 | const l3 = new Node(0) 16 | const l4 = new Node(0) 17 | 18 | test('Input: l3 = [0] & l4 = [0], Output: [0]', () => { 19 | expect(addTwoList(l3,l4)).toEqual({"next": null, "val": 0}); 20 | }); 21 | 22 | const l5 = {"val": 9, "next":{"val": 9, "next":{"val": 9, "next":{"val": 9, "next":{"val": 9, "next":{"val": 9, "next":{"val": 9, "next": null}}}}}}} 23 | const l6 = {"val": 9, "next":{"val": 9, "next":{"val": 9, "next":{"val": 9, "next": null}}}} 24 | 25 | test('Input: l5 = [9,9,9,9,9,9,9] & l6 = [9,9,9,9], Output: [8,9,9,9,0,0,0,1]', () => { 26 | expect(addTwoList(l5,l6)).toEqual({"val": 8, "next":{"val": 9, "next":{"val": 9, "next":{"val": 9, "next":{"val": 0, "next":{"val": 0, "next":{"val": 0, "next": {"val": 1, "next": null}}}}}}}}); 27 | }); -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/ruby/addTwoList.rb: -------------------------------------------------------------------------------- 1 | class ListNode 2 | attr_accessor :val, :next 3 | def initialize(val = 0, _next = nil) 4 | @val = val 5 | @next = _next 6 | end 7 | end 8 | 9 | def add_two_numbers(l1, l2) 10 | # type your code here 11 | end 12 | 13 | 14 | if __FILE__ == $PROGRAM_NAME 15 | puts "Expecting: 0" 16 | l1 = ListNode.new(0) 17 | l2 = ListNode.new(0) 18 | puts "=>", add_two_numbers(l1,l2) 19 | 20 | # Don't forget to add your own! 21 | end 22 | 23 | # Please add your pseudocode to this file 24 | # And a written explanation of your solution -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/ruby/spec/addTwoList_spec.rb: -------------------------------------------------------------------------------- 1 | require './addTwoList' 2 | 3 | RSpec.describe '#addTwoList' do 4 | 5 | n1 = ListNode.new(3) 6 | n2 = ListNode.new(4, n1) 7 | l1 = ListNode.new(2, n2) 8 | 9 | n3 = ListNode.new(4) 10 | n4 = ListNode.new(6, n3) 11 | l2 = ListNode.new(5, n4) 12 | 13 | n5 = ListNode.new(8) 14 | n6 = ListNode.new(0, n5) 15 | result_1 = ListNode.new(7, n6) 16 | 17 | 18 | p "results: #{add_two_numbers(l1,l2)}" 19 | 20 | it "Input: l1 = [2,4,3] & l2 = [5,6,4], Output: [7,0,8]" do 21 | expect(add_two_numbers(l1,l2).val).to eql(result_1.val) 22 | expect(add_two_numbers(l1,l2).next.val).to eql(result_1.next.val) 23 | expect(add_two_numbers(l1,l2).next.next.val).to eql(result_1.next.next.val) 24 | end 25 | end -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/solutions/addTwoList.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(val = null, next = null) { 3 | this.val = val; 4 | this.next = next; 5 | } 6 | } 7 | 8 | function addTwoList(l1, l2) { 9 | 10 | let node = null 11 | 12 | const carry = arguments[2] 13 | if (l1 || l2) { 14 | const val1 = l1 ? l1.val : 0 15 | const val2 = l2 ? l2.val : 0 16 | const next1 = l1 ? l1.next : null 17 | const next2 = l2 ? l2.next : null 18 | const val = carry ? val1 + val2 + 1 : val1 + val2 19 | node = new Node(val % 10) 20 | node.next = addTwoList(next1, next2, val >= 10) 21 | } else if (carry) { 22 | node = new Node(1) 23 | node.next = null 24 | } 25 | console.log(node) 26 | return node 27 | 28 | } 29 | 30 | if (require.main === module) { 31 | // add your own tests in here 32 | console.log("Expecting: { val: 0, next: null }"); 33 | console.log("=>", addTwoNumbers({ val: 0, next: null }, { val: 0, next: null })); 34 | 35 | } 36 | 37 | module.exports = { 38 | Node, 39 | addTwoList 40 | }; 41 | 42 | // More details here: https://leetcode.com/problems/add-two-numbers/solution/ -------------------------------------------------------------------------------- /17-week-13/01-day-3-to-5--add-two-numbers-list-nodes/solutions/addTwoList.rb: -------------------------------------------------------------------------------- 1 | class ListNode 2 | attr_accessor :val, :next 3 | def initialize(val = 0, _next = nil) 4 | @val = val 5 | @next = _next 6 | end 7 | end 8 | 9 | def add_two_numbers(l1, l2) 10 | n1, n2 = l1, l2 11 | 12 | current = answer = ListNode.new(nil) 13 | carry = 0 14 | 15 | while n1 || n2 || 0 < carry 16 | a = n1 ? n1.val : 0 17 | b = n2 ? n2.val : 0 18 | x = a + b + carry 19 | 20 | carry = x / 10 21 | x -= 10 if 0 < carry 22 | 23 | node = ListNode.new(x) 24 | current&.next = node 25 | current = node 26 | 27 | n1, n2 = n1&.next, n2&.next 28 | end 29 | answer.next 30 | end 31 | 32 | 33 | if __FILE__ == $PROGRAM_NAME 34 | puts "Expecting: 0" 35 | l1 = ListNode.new(0) 36 | l2 = ListNode.new(0) 37 | puts "=>", add_two_numbers(l1,l2) 38 | 39 | # Don't forget to add your own! 40 | end 41 | 42 | # More details here: https://leetcode.com/problems/add-two-numbers/solution/ -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json 5 | .DS_store -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/javascript/longSubString.js: -------------------------------------------------------------------------------- 1 | function lengthOfLongestSubstring(s) { 2 | // type your code here 3 | } 4 | 5 | if (require.main === module) { 6 | 7 | // add your own tests in here 8 | console.log("Expecting: 3"); 9 | console.log("=>", lengthOfLongestSubstring("abcabcbb")); 10 | 11 | } 12 | 13 | module.exports = lengthOfLongestSubstring 14 | 15 | // Please add your pseudocode to this file 16 | // And a written explanation of your solution -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "length_of_longest_substring", 3 | "version": "1.0.0", 4 | "description": "lengthOfLongestSubstring", 5 | "main": "longSubString.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/javascript/tests/longSubString.test.js: -------------------------------------------------------------------------------- 1 | const lengthOfLongestSubstring = require('../longSubString'); 2 | 3 | let s1 = "abcabcbb" 4 | let s2 = "bbbbb" 5 | let s3 = "pwwkew" 6 | let s4 = "" 7 | 8 | 9 | test('Input: s1 = "abcabcbb", Output: 3', () => { 10 | expect(lengthOfLongestSubstring(s1)).toEqual(3); 11 | }); 12 | 13 | test('Input: s2 = "bbbbb", Output: 1', () => { 14 | expect(lengthOfLongestSubstring(s2)).toEqual(1); 15 | }); 16 | 17 | test('Input: s3 = "pwwkew", Output: 3', () => { 18 | expect(lengthOfLongestSubstring(s3)).toEqual(3); 19 | }); 20 | 21 | test('Input: s4 = "", Output: 0', () => { 22 | expect(lengthOfLongestSubstring(s4)).toEqual(0); 23 | }); -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/ruby/longSubString.rb: -------------------------------------------------------------------------------- 1 | def length_of_longest_substring(s) 2 | # type your code here 3 | end 4 | 5 | 6 | if __FILE__ == $PROGRAM_NAME 7 | 8 | puts "Expecting: 3" 9 | puts "=>", length_of_longest_substring("abcabcbb") 10 | 11 | # Don't forget to add your own! 12 | end 13 | 14 | # Please add your pseudocode to this file 15 | # And a written explanation of your solution -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/ruby/spec/longSubString_spec.rb: -------------------------------------------------------------------------------- 1 | require './longSubString' 2 | 3 | RSpec.describe '#length_of_longest_substring' do 4 | 5 | s1 = "abcabcbb" 6 | s2 = "bbbbb" 7 | s3 = "pwwkew" 8 | s4 = "" 9 | 10 | p "results: #{length_of_longest_substring(s1)}" 11 | 12 | it "Input: s1 = abcabcbb, Output: 3" do 13 | expect(length_of_longest_substring(s1)).to eql(3) 14 | end 15 | 16 | p "results: #{length_of_longest_substring(s2)}" 17 | 18 | it "Input: s2 = bbbbb, Output: 1" do 19 | expect(length_of_longest_substring(s2)).to eql(1) 20 | end 21 | 22 | p "results: #{length_of_longest_substring(s3)}" 23 | 24 | it "Input: s3 = pwwkew, Output: 3" do 25 | expect(length_of_longest_substring(s3)).to eql(3) 26 | end 27 | 28 | 29 | p "results: #{length_of_longest_substring(s4)}" 30 | 31 | it "Input: s4 = "", Output: 0" do 32 | expect(length_of_longest_substring(s4)).to eql(0) 33 | end 34 | end -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/solutions/longSubString.js: -------------------------------------------------------------------------------- 1 | function lengthOfLongestSubstring(s) { 2 | 3 | let map = {} 4 | let start = 0 5 | let maxLen = 0 6 | let arr = s.split('') 7 | 8 | for (i=0; i < s.length; i++) { 9 | let current = map[arr[i]] 10 | if (current!=null && start <= current) { 11 | start = current + 1 12 | } else { 13 | maxLen = Math.max(maxLen, i - start + 1) 14 | } 15 | 16 | map[arr[i]] = i 17 | } 18 | 19 | return maxLen 20 | } 21 | 22 | if (require.main === module) { 23 | 24 | console.log("Expecting: 3"); 25 | console.log("=>", lengthOfLongestSubstring("abcabcbb")); 26 | 27 | } 28 | 29 | module.exports = lengthOfLongestSubstring -------------------------------------------------------------------------------- /18-week-14/00-day-1-to-2--longest-substring-without-repeating-characters/solutions/longSubString.rb: -------------------------------------------------------------------------------- 1 | def length_of_longest_substring(s) 2 | return s.size if s.size < 2 3 | 4 | queue, hash = [], {} 5 | s.each_char.reduce(-Float::INFINITY) do |max, c| 6 | hash.delete(char = queue.shift) until queue.empty? || char.eql?(c) if hash.key?(c) 7 | 8 | [max, (queue << hash[c] = c).size].max 9 | end 10 | end 11 | 12 | 13 | if __FILE__ == $PROGRAM_NAME 14 | 15 | puts "Expecting: 3" 16 | puts "=>", length_of_longest_substring("abcabcbb") 17 | 18 | # Don't forget to add your own! 19 | end 20 | -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | 3 | node_modules/ 4 | package-lock.json 5 | .DS_store -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/18-week-14/01-day-3-to-5--validate-bst/example-1.png -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/learn-co-curriculum/postwork-data-structures-and-algorithms/706e82e4822df65c0ce54d7fa49e861db23a5a5b/18-week-14/01-day-3-to-5--validate-bst/example-2.png -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "valid_bts", 3 | "version": "1.0.0", 4 | "description": "validBTS", 5 | "main": "validBTS.js", 6 | "dependencies": { 7 | "jest": "^26.6.3" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "none" 16 | }, 17 | "author": "flatiron", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/javascript/tests/validBTS.test.js: -------------------------------------------------------------------------------- 1 | const { Node , isValidBST } = require('../validBTS'); 2 | 3 | describe('example test cases', () => { 4 | // Convenience helper to construct a tree. 5 | const T = (v, l, r) => new Node(v, l, r); 6 | 7 | it('should validate the examples', () => { 8 | expect(isValidBST(T(2, T(1), T(3)))).toEqual(true); 9 | expect(isValidBST(T(5, T(1), T(4, T(3), T(6))))).toEqual(false); 10 | }); 11 | }); -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/javascript/validBTS.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(val, left = null, right = null){ 3 | this.val = val; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | function isValidBST(root) { 10 | // type your code here 11 | } 12 | 13 | if (require.main === module) { 14 | 15 | // add your own tests in here 16 | const T = (v, l, r) => new Node(v, l, r) 17 | 18 | console.log("Expecting: true"); 19 | console.log("=>", isValidBST(T(2, T(1), T(3)))); 20 | 21 | } 22 | 23 | module.exports = { 24 | isValidBST, 25 | Node 26 | } 27 | 28 | // Please add your pseudocode to this file 29 | // And a written explanation of your solution -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/ruby/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 6 | 7 | gem 'rspec' -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/ruby/spec/valdiBTS_spec.rb: -------------------------------------------------------------------------------- 1 | require './validBTS' 2 | 3 | RSpec.describe '#validBTS' do 4 | 5 | it "should validate the example-1" do 6 | def T(v,l,r) 7 | return Node.new(v, l, r) 8 | end 9 | 10 | expect(is_valid_bst(T(2, T(1, nil, nil), T(3, nil, nil)))).to eql(true) 11 | end 12 | 13 | it "should validate the example-2" do 14 | def T(v,l,r) 15 | return Node.new(v, l, r) 16 | end 17 | 18 | expect(is_valid_bst(T(5, T(1, nil, nil), T(4, T(3, nil, nil), T(6, nil, nil))))).to eql(false) 19 | end 20 | 21 | end -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/ruby/validBTS.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :val, :left, :right 3 | def initialize(val = 0, left = nil, right = nil) 4 | @val = val 5 | @left = left 6 | @right = right 7 | end 8 | end 9 | 10 | def is_valid_bst(root) 11 | # type your code here 12 | end 13 | 14 | if __FILE__ == $PROGRAM_NAME 15 | 16 | puts "Expecting: true" 17 | def T(v,l,r) 18 | return Node.new(v, l, r) 19 | end 20 | puts "=>", is_valid_bst(T(2, T(1, nil, nil), T(3, nil, nil))) 21 | 22 | # Don't forget to add your own! 23 | end 24 | 25 | # Please add your pseudocode to this file 26 | # And a written explanation of your solution -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/solutions/validBTS.js: -------------------------------------------------------------------------------- 1 | class Node { 2 | constructor(val, left = null, right = null){ 3 | this.val = val; 4 | this.left = left; 5 | this.right = right; 6 | } 7 | } 8 | 9 | const isValid = (root, low, high) => { 10 | if(!root) { 11 | return true; 12 | } 13 | if(root.val <= low || root.val >= high) { 14 | return false; 15 | } 16 | return (isValid(root.left, low, root.val) && isValid(root.right, root.val, high)); 17 | 18 | } 19 | 20 | function isValidBST(root) { 21 | return isValid(root, -Infinity, Infinity); 22 | } 23 | 24 | if (require.main === module) { 25 | 26 | // add your own tests in here 27 | const T = (v, l, r) => new Node(v, l, r) 28 | 29 | console.log("Expecting: true"); 30 | console.log("=>", isValidBST(T(2, T(1), T(3)))); 31 | 32 | } 33 | 34 | module.exports = { 35 | isValidBST, 36 | Node 37 | } -------------------------------------------------------------------------------- /18-week-14/01-day-3-to-5--validate-bst/solutions/validBTS.rb: -------------------------------------------------------------------------------- 1 | class Node 2 | attr_accessor :val, :left, :right 3 | def initialize(val = 0, left = nil, right = nil) 4 | @val = val 5 | @left = left 6 | @right = right 7 | end 8 | end 9 | 10 | def isValid(root, low, high) 11 | !root || 12 | low < root.val && 13 | root.val < high && 14 | isValid(root.left, low, root.val) && 15 | isValid(root.right, root.val, high) 16 | end 17 | 18 | def is_valid_bst(root) 19 | return isValid(root, -Float::INFINITY, Float::INFINITY) 20 | end 21 | 22 | if __FILE__ == $PROGRAM_NAME 23 | 24 | puts "Expecting: true" 25 | def T(v,l,r) 26 | return Node.new(v, l, r) 27 | end 28 | puts "=>", is_valid_bst(T(2, T(1, nil, nil), T(3, nil, nil))) 29 | 30 | end 31 | -------------------------------------------------------------------------------- /19-week-15/00-week-15-algo-practices/README.md: -------------------------------------------------------------------------------- 1 | # Week-15-algo-practices 2 | 3 | More Practice: 4 | - [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) 5 | - First just solve it however possible. BONUS: Use DP to solve. Calculate Big-O. 6 | - [House Robber](https://leetcode.com/problems/house-robber/) 7 | - First just solve it however possible. BONUS: Use DP to solve. Calculate Big-O. 8 | - [Is Subsequence](https://leetcode.com/problems/is-subsequence/) 9 | - Solve however possible, then aim for O(n). Calculate Big-O. 10 | - [Unique Paths](https://leetcode.com/problems/unique-paths-iii/) 11 | - [Egg Dropping Problem](https://leetcode.com/problems/super-egg-drop/) 12 | -------------------------------------------------------------------------------- /20-pairing-exercises-5/00-code-comparison/README.md: -------------------------------------------------------------------------------- 1 | # Code Comparison 2 | 3 | ## Introduction 4 | 5 | For this activity, you and your partner will each choose a problem that you have 6 | both completed. Either in person or over video chat via screenshare: 7 | 8 | - Explain your solutions to each other 9 | - Point out the differences in how you approached solving the problem 10 | - Discuss at least one part of your partner's solution that you liked and have 11 | learned from 12 | - Did your partner do something you didn't even think of? 13 | - Is there something about the way they code that jumps out to you? For 14 | example, is their code extremely readable without comments? 15 | - Is their solution more efficient, e.g. better time complexity or uses less 16 | memory? 17 | - Discuss at least one part of your partner's solution which you think can be 18 | improved and why 19 | - Is the solution difficult to understand without heavy commenting? 20 | - Does it contain redundant/unused code? 21 | - Should helper methods have been used? 22 | - Could it easily be made more efficient? For example, were the best data 23 | structures used to solve the problem? 24 | --------------------------------------------------------------------------------