Showing preview only (1,621K chars total). Download the full file or copy to clipboard to get everything.
Repository: donnemartin/interactive-coding-challenges
Branch: master
Commit: 358f2cc60426
Files: 499
Total size: 1.5 MB
Directory structure:
gitextract_0a45doj9/
├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── __init__.py
├── anki_cards/
│ └── Coding.apkg
├── arrays_strings/
│ ├── __init__.py
│ ├── compress/
│ │ ├── __init__.py
│ │ ├── compress_challenge.ipynb
│ │ ├── compress_solution.ipynb
│ │ └── test_compress.py
│ ├── compress_alt/
│ │ ├── __init__.py
│ │ ├── better_compress_challenge.ipynb
│ │ ├── better_compress_solution.ipynb
│ │ └── test_compress.py
│ ├── fizz_buzz/
│ │ ├── __init__.py
│ │ ├── fizz_buzz_challenge.ipynb
│ │ ├── fizz_buzz_solution.ipynb
│ │ └── test_fizz_buzz.py
│ ├── hash_map/
│ │ ├── __init__.py
│ │ ├── hash_map_challenge.ipynb
│ │ ├── hash_map_solution.ipynb
│ │ └── test_hash_map.py
│ ├── permutation/
│ │ ├── __init__.py
│ │ ├── permutation_challenge.ipynb
│ │ ├── permutation_solution.ipynb
│ │ └── test_permutation_solution.py
│ ├── priority_queue/
│ │ ├── __init__.py
│ │ ├── priority_queue.py
│ │ ├── priority_queue_challenge.ipynb
│ │ ├── priority_queue_solution.ipynb
│ │ └── test_priority_queue.py
│ ├── reverse_string/
│ │ ├── __init__.py
│ │ ├── reverse_string.cpp
│ │ ├── reverse_string_challenge.ipynb
│ │ ├── reverse_string_solution.ipynb
│ │ └── test_reverse_string.py
│ ├── rotation/
│ │ ├── __init__.py
│ │ ├── rotation_challenge.ipynb
│ │ ├── rotation_solution.ipynb
│ │ └── test_rotation.py
│ ├── str_diff/
│ │ ├── __init__.py
│ │ ├── str_diff_challenge.ipynb
│ │ ├── str_diff_solution.ipynb
│ │ └── test_str_diff.py
│ ├── two_sum/
│ │ ├── __init__.py
│ │ ├── test_two_sum.py
│ │ ├── two_sum_challenge.ipynb
│ │ └── two_sum_solution.ipynb
│ └── unique_chars/
│ ├── __init__.py
│ ├── test_unique_chars.py
│ ├── unique_chars_challenge.ipynb
│ └── unique_chars_solution.ipynb
├── bit_manipulation/
│ ├── __init__.py
│ ├── bit/
│ │ ├── __init__.py
│ │ ├── bit_challenge.ipynb
│ │ ├── bit_solution.ipynb
│ │ └── test_bit.py
│ ├── bits_to_flip/
│ │ ├── __init__.py
│ │ ├── bits_to_flip_challenge.ipynb
│ │ ├── bits_to_flip_solution.ipynb
│ │ └── test_bits_to_flip.py
│ ├── draw_line/
│ │ ├── __init__.py
│ │ ├── draw_line_challenge.ipynb
│ │ ├── draw_line_solution.ipynb
│ │ └── test_draw_line.py
│ ├── flip_bit/
│ │ ├── __init__.py
│ │ ├── flip_bit_challenge.ipynb
│ │ ├── flip_bit_solution.ipynb
│ │ └── test_flip_bit.py
│ ├── get_next/
│ │ ├── __init__.py
│ │ ├── get_next_challenge.ipynb
│ │ ├── get_next_solution.ipynb
│ │ └── test_get_next_largest.py
│ ├── insert_m_into_n/
│ │ ├── __init__.py
│ │ ├── insert_m_into_n_challenge.ipynb
│ │ ├── insert_m_into_n_solution.ipynb
│ │ └── test_insert_m_into_n.py
│ ├── pairwise_swap/
│ │ ├── __init__.py
│ │ ├── pairwise_swap_challenge.ipynb
│ │ ├── pairwise_swap_solution.ipynb
│ │ └── test_pairwise_swap.py
│ └── print_binary/
│ ├── __init__.py
│ ├── print_binary_challenge.ipynb
│ ├── print_binary_solution.ipynb
│ └── test_print_binary.py
├── graphs_trees/
│ ├── __init__.py
│ ├── bst/
│ │ ├── __init__.py
│ │ ├── bst.py
│ │ ├── bst_challenge.ipynb
│ │ ├── bst_solution.ipynb
│ │ ├── dfs.py
│ │ └── test_bst.py
│ ├── bst_min/
│ │ ├── __init__.py
│ │ ├── bst_min_challenge.ipynb
│ │ ├── bst_min_solution.ipynb
│ │ └── test_bst_min.py
│ ├── bst_second_largest/
│ │ ├── __init__.py
│ │ ├── bst_second_largest_challenge.ipynb
│ │ ├── bst_second_largest_solution.ipynb
│ │ └── test_bst_second_largest.py
│ ├── bst_successor/
│ │ ├── __init__.py
│ │ ├── bst_successor_challenge.ipynb
│ │ ├── bst_successor_solution.ipynb
│ │ └── test_bst_successor.py
│ ├── bst_validate/
│ │ ├── __init__.py
│ │ ├── bst_validate_challenge.ipynb
│ │ ├── bst_validate_solution.ipynb
│ │ └── test_bst_validate.py
│ ├── check_balance/
│ │ ├── __init__.py
│ │ ├── check_balance_challenge.ipynb
│ │ ├── check_balance_solution.ipynb
│ │ └── test_check_balance.py
│ ├── graph/
│ │ ├── __init__.py
│ │ ├── graph.py
│ │ ├── graph_challenge.ipynb
│ │ ├── graph_solution.ipynb
│ │ └── test_graph.py
│ ├── graph_bfs/
│ │ ├── __init__.py
│ │ ├── bfs_challenge.ipynb
│ │ ├── bfs_solution.ipynb
│ │ └── test_bfs.py
│ ├── graph_build_order/
│ │ ├── __init__.py
│ │ ├── build_order_challenge.ipynb
│ │ ├── build_order_solution.ipynb
│ │ └── test_build_order.py
│ ├── graph_dfs/
│ │ ├── __init__.py
│ │ ├── dfs_challenge.ipynb
│ │ ├── dfs_solution.ipynb
│ │ └── test_dfs.py
│ ├── graph_path_exists/
│ │ ├── __init__.py
│ │ ├── path_exists_challenge.ipynb
│ │ ├── path_exists_solution.ipynb
│ │ └── test_path_exists.py
│ ├── graph_shortest_path/
│ │ ├── __init__.py
│ │ ├── graph_shortest_path_challenge.ipynb
│ │ ├── graph_shortest_path_solution.ipynb
│ │ ├── priority_queue.py
│ │ └── test_shortest_path.py
│ ├── graph_shortest_path_unweighted/
│ │ ├── __init__.py
│ │ ├── shortest_path_challenge.ipynb
│ │ ├── shortest_path_solution.ipynb
│ │ └── test_shortest_path.py
│ ├── invert_tree/
│ │ ├── __init__.py
│ │ ├── invert_tree_challenge.ipynb
│ │ ├── invert_tree_solution.ipynb
│ │ └── test_invert_tree.py
│ ├── min_heap/
│ │ ├── __init__.py
│ │ ├── min_heap.py
│ │ ├── min_heap_challenge.ipynb
│ │ ├── min_heap_solution.ipynb
│ │ └── test_min_heap.py
│ ├── tree_bfs/
│ │ ├── __init__.py
│ │ ├── bfs_challenge.ipynb
│ │ ├── bfs_solution.ipynb
│ │ └── test_bfs.py
│ ├── tree_dfs/
│ │ ├── __init__.py
│ │ ├── dfs_challenge.ipynb
│ │ ├── dfs_solution.ipynb
│ │ └── test_dfs.py
│ ├── tree_height/
│ │ ├── __init__.py
│ │ ├── height.py
│ │ ├── height_challenge.ipynb
│ │ ├── height_solution.ipynb
│ │ └── test_height.py
│ ├── tree_lca/
│ │ ├── __init__.py
│ │ ├── test_lca.py
│ │ ├── tree_lca_challenge.ipynb
│ │ └── tree_lca_solution.ipynb
│ ├── tree_level_lists/
│ │ ├── __init__.py
│ │ ├── test_tree_level_lists.py
│ │ ├── tree_level_lists_challenge.ipynb
│ │ └── tree_level_lists_solution.ipynb
│ ├── trie/
│ │ ├── __init__.py
│ │ ├── test_trie.py
│ │ ├── trie.py
│ │ ├── trie_challenge.ipynb
│ │ └── trie_solution.ipynb
│ └── utils/
│ ├── __init__.py
│ ├── captured_output.py
│ └── results.py
├── linked_lists/
│ ├── __init__.py
│ ├── add_reverse/
│ │ ├── __init__.py
│ │ ├── add_reverse_challenge.ipynb
│ │ ├── add_reverse_solution.ipynb
│ │ └── test_add_reverse.py
│ ├── delete_mid/
│ │ ├── __init__.py
│ │ ├── delete_mid_challenge.ipynb
│ │ ├── delete_mid_solution.ipynb
│ │ └── test_delete_mid.py
│ ├── find_loop_start/
│ │ ├── __init__.py
│ │ ├── find_loop_start_challenge.ipynb
│ │ ├── find_loop_start_solution.ipynb
│ │ └── test_find_loop_start.py
│ ├── kth_to_last_elem/
│ │ ├── __init__.py
│ │ ├── kth_to_last_elem_challenge.ipynb
│ │ ├── kth_to_last_elem_solution.ipynb
│ │ └── test_kth_to_last_elem.py
│ ├── linked_list/
│ │ ├── __init__.py
│ │ ├── linked_list.py
│ │ ├── linked_list_challenge.ipynb
│ │ ├── linked_list_solution.ipynb
│ │ └── test_linked_list.py
│ ├── palindrome/
│ │ ├── __init__.py
│ │ ├── palindrome_challenge.ipynb
│ │ ├── palindrome_solution.ipynb
│ │ └── test_palindrome.py
│ ├── partition/
│ │ ├── __init__.py
│ │ ├── partition_challenge.ipynb
│ │ ├── partition_solution.ipynb
│ │ └── test_partition.py
│ └── remove_duplicates/
│ ├── __init__.py
│ ├── remove_duplicates_challenge.ipynb
│ ├── remove_duplicates_solution.ipynb
│ └── test_remove_duplicates.py
├── math_probability/
│ ├── add_digits/
│ │ ├── __init__.py
│ │ ├── add_digits_challenge.ipynb
│ │ ├── add_digits_solution.ipynb
│ │ └── test_add_digits.py
│ ├── check_prime/
│ │ ├── __init__.py
│ │ ├── check_prime_challenge.ipynb
│ │ ├── check_prime_solution.ipynb
│ │ └── test_check_prime.py
│ ├── generate_primes/
│ │ ├── __init__.py
│ │ ├── check_prime_challenge.ipynb
│ │ ├── check_prime_solution.ipynb
│ │ └── test_generate_primes.py
│ ├── math_ops/
│ │ ├── __init__.py
│ │ ├── math_ops_challenge.ipynb
│ │ ├── math_ops_solution.ipynb
│ │ └── test_math_ops.py
│ ├── power_two/
│ │ ├── __init__.py
│ │ ├── power_two_challenge.ipynb
│ │ ├── power_two_solution.ipynb
│ │ └── test_is_power_of_two.py
│ ├── sub_two/
│ │ ├── __init__.py
│ │ ├── sub_two_challenge.ipynb
│ │ ├── sub_two_solution.ipynb
│ │ └── test_sub_two.py
│ └── sum_two/
│ ├── __init__.py
│ ├── sum_two_challenge.ipynb
│ ├── sum_two_solution.ipynb
│ └── test_sum_two.py
├── online_judges/
│ ├── __init__.py
│ ├── assign_cookies/
│ │ ├── __init__.py
│ │ ├── assign_cookies_challenge.ipynb
│ │ ├── assign_cookies_solution.ipynb
│ │ └── test_assign_cookie.py
│ ├── busiest_period/
│ │ ├── __init__.py
│ │ ├── busiest_period_challenge.ipynb
│ │ ├── busiest_period_solution.ipynb
│ │ └── test_find_busiest_period.py
│ ├── island_perimeter/
│ │ ├── __init__.py
│ │ ├── island_perimeter_challenge.ipynb
│ │ ├── island_perimeter_solution.ipynb
│ │ └── test_island_perimeter.py
│ ├── license_key/
│ │ ├── __init__.py
│ │ ├── format_license_key_challenge.ipynb
│ │ ├── format_license_key_solution.ipynb
│ │ └── test_format_license_key.py
│ ├── longest_abs_file_path/
│ │ ├── __init__.py
│ │ ├── longest_path_challenge.ipynb
│ │ ├── longest_path_solution.ipynb
│ │ └── test_length_longest_path.py
│ ├── longest_substr_k_distinct/
│ │ ├── __init__.py
│ │ ├── longest_substr_challenge.ipynb
│ │ ├── longest_substr_solution.ipynb
│ │ └── test_longest_substr.py
│ ├── math_ops/
│ │ ├── __init__.py
│ │ ├── math_ops_challenge.ipynb
│ │ ├── math_ops_solution.ipynb
│ │ └── test_math_ops.py
│ ├── max_profit/
│ │ ├── __init__.py
│ │ ├── max_profit_challenge.ipynb
│ │ ├── max_profit_solution.ipynb
│ │ └── test_max_profit.py
│ ├── maximizing_xor/
│ │ ├── __init__.py
│ │ ├── maximizing_xor_challenge.ipynb
│ │ ├── maximizing_xor_solution.ipynb
│ │ └── test_maximizing_xor.py
│ ├── merge_ranges/
│ │ ├── __init__.py
│ │ ├── merge_ranges_challenge.ipynb
│ │ ├── merge_ranges_solution.ipynb
│ │ └── test_merge_ranges.py
│ ├── move_zeroes/
│ │ ├── __init__.py
│ │ ├── move_zeroes_challenge.ipynb
│ │ ├── move_zeroes_solution.ipynb
│ │ └── test_move_zeroes.py
│ ├── mult_other_numbers/
│ │ ├── __init__.py
│ │ ├── mult_other_numbers_challenge.ipynb
│ │ ├── mult_other_numbers_solution.ipynb
│ │ └── test_mult_other_numbers.py
│ ├── nim/
│ │ ├── __init__.py
│ │ ├── nim_challenge.ipynb
│ │ ├── nim_solution.ipynb
│ │ └── test_can_win_nim.py
│ ├── prod_three/
│ │ ├── __init__.py
│ │ ├── prod_three_challenge.ipynb
│ │ ├── prod_three_solution.ipynb
│ │ └── test_prod_three.py
│ ├── ransom_note/
│ │ ├── __init__.py
│ │ ├── ransom_note_challenge.ipynb
│ │ ├── ransom_note_solution.ipynb
│ │ └── test_ransom_note.py
│ ├── sentence_screen_fit/
│ │ ├── __init__.py
│ │ ├── sentence_screen_fit_challenge.ipynb
│ │ ├── sentence_screen_fit_solution.ipynb
│ │ └── test_count_sentence_fit.py
│ ├── str_diff/
│ │ ├── __init__.py
│ │ ├── str_diff_challenge.ipynb
│ │ ├── str_diff_solution.ipynb
│ │ └── test_str_diff.py
│ ├── sub_two/
│ │ ├── sub_two_challenge.ipynb
│ │ ├── sub_two_solution.ipynb
│ │ └── test_sub_two.py
│ ├── sum_two/
│ │ ├── sum_two_challenge.ipynb
│ │ ├── sum_two_solution.ipynb
│ │ └── test_sum_two.py
│ └── utopian_tree/
│ ├── __init__.py
│ ├── test_utopian_tree.py
│ ├── utopian_tree_challenge.ipynb
│ └── utopian_tree_solution.ipynb
├── recursion_dynamic/
│ ├── __init__.py
│ ├── coin_change/
│ │ ├── __init__.py
│ │ ├── coin_change_challenge.ipynb
│ │ ├── coin_change_solution.ipynb
│ │ └── test_coin_change.py
│ ├── coin_change_min/
│ │ ├── __init__.py
│ │ ├── coin_change_min_challenge.ipynb
│ │ ├── coin_change_min_solution.ipynb
│ │ └── test_coin_change_min.py
│ ├── coin_change_ways/
│ │ ├── __init__.py
│ │ ├── coin_change_ways_challenge.ipynb
│ │ ├── coin_change_ways_solution.ipynb
│ │ └── test_coin_change_ways.py
│ ├── fibonacci/
│ │ ├── __init__.py
│ │ ├── fibonacci_challenge.ipynb
│ │ ├── fibonacci_solution.ipynb
│ │ └── test_fibonacci.py
│ ├── grid_path/
│ │ ├── __init__.py
│ │ ├── grid_path_challenge.ipynb
│ │ ├── grid_path_solution.ipynb
│ │ └── test_grid_path.py
│ ├── hanoi/
│ │ ├── __init__.py
│ │ ├── hanoi_challenge.ipynb
│ │ ├── hanoi_solution.ipynb
│ │ └── test_hanoi.py
│ ├── knapsack_01/
│ │ ├── __init__.py
│ │ ├── knapsack_challenge.ipynb
│ │ ├── knapsack_solution.ipynb
│ │ └── test_knapsack.py
│ ├── knapsack_unbounded/
│ │ ├── __init__.py
│ │ ├── knapsack_unbounded_challenge.ipynb
│ │ ├── knapsack_unbounded_solution.ipynb
│ │ └── test_knapsack_unbounded.py
│ ├── longest_common_subsequence/
│ │ ├── __init__.py
│ │ ├── longest_common_subseq_challenge.ipynb
│ │ ├── longest_common_subseq_solution.ipynb
│ │ └── test_longest_common_subseq.py
│ ├── longest_inc_subseq/
│ │ ├── __init__.py
│ │ ├── longest_inc_subseq_challenge.ipynb
│ │ ├── longest_inc_subseq_solution.ipynb
│ │ └── test_longest_increasing_subseq.py
│ ├── longest_substr_k_distinct/
│ │ ├── __init__.py
│ │ ├── longest_substr_challenge.ipynb
│ │ ├── longest_substr_solution.ipynb
│ │ └── test_longest_substr.py
│ ├── longest_substring/
│ │ ├── __init__.py
│ │ ├── longest_common_substr_challenge.ipynb
│ │ ├── longest_common_substr_solution.ipynb
│ │ └── test_longest_common_substr.py
│ ├── magic_index/
│ │ ├── __init__.py
│ │ ├── magic_index_challenge.ipynb
│ │ ├── magic_index_solution.ipynb
│ │ └── test_find_magic_index.py
│ ├── matrix_mult/
│ │ ├── __init__.py
│ │ ├── find_min_cost_challenge.ipynb
│ │ ├── find_min_cost_solution.ipynb
│ │ └── test_find_min_cost.py
│ ├── max_profit_k/
│ │ ├── __init__.py
│ │ ├── max_profit_challenge.ipynb
│ │ ├── max_profit_solution.ipynb
│ │ └── test_max_profit.py
│ ├── n_pairs_parentheses/
│ │ ├── __init__.py
│ │ ├── n_pairs_parentheses_challenge.ipynb
│ │ ├── n_pairs_parentheses_solution.ipynb
│ │ └── test_n_pairs_parentheses.py
│ ├── permutations/
│ │ ├── __init__.py
│ │ ├── permutations_challenge.ipynb
│ │ ├── permutations_solution.ipynb
│ │ └── test_permutations.py
│ ├── power_set/
│ │ ├── __init__.py
│ │ ├── power_set_challenge.ipynb
│ │ ├── power_set_solution.ipynb
│ │ └── test_power_set.py
│ └── steps/
│ ├── __init__.py
│ ├── steps_challenge.ipynb
│ ├── steps_solution.ipynb
│ └── test_steps.py
├── requirements.txt
├── sorting_searching/
│ ├── __init__.py
│ ├── anagrams/
│ │ ├── __init__.py
│ │ ├── anagrams_challenge.ipynb
│ │ ├── anagrams_solution.ipynb
│ │ └── test_anagrams.py
│ ├── insertion_sort/
│ │ ├── __init__.py
│ │ ├── insertion_sort_challenge.ipynb
│ │ ├── insertion_sort_solution.ipynb
│ │ └── test_insertion_sort.py
│ ├── merge_into/
│ │ ├── __init__.py
│ │ ├── merge_into_challenge.ipynb
│ │ ├── merge_into_solution.ipynb
│ │ └── test_merge_into.py
│ ├── merge_sort/
│ │ ├── __init__.py
│ │ ├── merge_sort_challenge.ipynb
│ │ ├── merge_sort_solution.ipynb
│ │ └── test_merge_sort.py
│ ├── new_int/
│ │ ├── __init__.py
│ │ ├── new_int_challenge.ipynb
│ │ ├── new_int_solution.ipynb
│ │ └── test_new_int.py
│ ├── quick_sort/
│ │ ├── __init__.py
│ │ ├── quick_sort_challenge.ipynb
│ │ ├── quick_sort_solution.ipynb
│ │ └── test_quick_sort.py
│ ├── radix_sort/
│ │ ├── __init__.py
│ │ ├── radix_sort_challenge.ipynb
│ │ ├── radix_sort_solution.ipynb
│ │ └── test_radix_sort.py
│ ├── rotated_array_search/
│ │ ├── __init__.py
│ │ ├── rotated_array_search_challenge.ipynb
│ │ ├── rotated_array_search_solution.ipynb
│ │ └── test_search_sorted_array.py
│ ├── search_sorted_matrix/
│ │ ├── __init__.py
│ │ ├── search_sorted_matrix_challenge.ipynb
│ │ ├── search_sorted_matrix_solution.ipynb
│ │ └── test_search_sorted_matrix.py
│ └── selection_sort/
│ ├── __init__.py
│ ├── selection_sort_challenge.ipynb
│ ├── selection_sort_solution.ipynb
│ └── test_selection_sort.py
├── stacks_queues/
│ ├── __init__.py
│ ├── n_stacks/
│ │ ├── __init__.py
│ │ ├── n_stacks_challenge.ipynb
│ │ ├── n_stacks_solution.ipynb
│ │ └── test_n_stacks.py
│ ├── queue_from_stacks/
│ │ ├── __init__.py
│ │ ├── queue_from_stacks_challenge.ipynb
│ │ ├── queue_from_stacks_solution.ipynb
│ │ └── test_queue_from_stacks.py
│ ├── queue_list/
│ │ ├── __init__.py
│ │ ├── queue_list.py
│ │ ├── queue_list_challenge.ipynb
│ │ ├── queue_list_solution.ipynb
│ │ └── test_queue_list.py
│ ├── set_of_stacks/
│ │ ├── __init__.py
│ │ ├── set_of_stacks_challenge.ipynb
│ │ ├── set_of_stacks_solution.ipynb
│ │ └── test_set_of_stacks.py
│ ├── sort_stack/
│ │ ├── __init__.py
│ │ ├── sort_stack_challenge.ipynb
│ │ ├── sort_stack_solution.ipynb
│ │ └── test_sort_stack.py
│ ├── stack/
│ │ ├── __init__.py
│ │ ├── stack.py
│ │ ├── stack_challenge.ipynb
│ │ ├── stack_solution.ipynb
│ │ └── test_stack.py
│ └── stack_min/
│ ├── __init__.py
│ ├── stack_min_challenge.ipynb
│ ├── stack_min_solution.ipynb
│ └── test_stack_min.py
├── staging/
│ ├── README.md
│ ├── __init__.py
│ ├── arrays_strings/
│ │ ├── __init__.py
│ │ └── reverse_words/
│ │ ├── __init__.py
│ │ ├── reverse_words_challenge.ipynb
│ │ ├── reverse_words_solution.ipynb
│ │ └── reverse_words_solution.py
│ ├── graphs_trees/
│ │ ├── __init__.py
│ │ └── binary_tree/
│ │ ├── __init__.py
│ │ ├── binary_search_tree.py
│ │ ├── binary_tree_challenge.ipynb
│ │ ├── binary_tree_solution.ipynb
│ │ └── test_binary_search_tree.py
│ ├── linked_lists/
│ │ └── __init__.py
│ ├── online_judges/
│ │ └── __init__.py
│ ├── recursion_dynamic/
│ │ └── __init__.py
│ ├── sorting_searching/
│ │ ├── __init__.py
│ │ └── group_ordered/
│ │ ├── __init__.py
│ │ ├── group_ordered_challenge.ipynb
│ │ ├── group_ordered_solution.ipynb
│ │ └── test_group_ordered.py
│ └── stacks_queues/
│ └── __init__.py
└── templates/
├── __init__.py
├── foo_challenge.ipynb
├── foo_solution.ipynb
└── test_foo.py
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
*.ipynb linguist-language=Python
================================================
FILE: .gitignore
================================================
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython notebook
.ipynb_checkpoints
# Repo scratch directory
scratch/
# IPython Notebook templates
template.ipynb
================================================
FILE: CONTRIBUTING.md
================================================
Contributing
============
Contributions are welcome!
**Please carefully read this page to make the code review process go as smoothly as possible and to maximize the likelihood of your contribution being merged.**
## Bug Reports
For bug reports or requests [submit an issue](https://github.com/donnemartin/interactive-coding-challenges/issues).
## Pull Requests
**Please follow the general [Repo Structure](https://github.com/donnemartin/interactive-coding-challenges#repo-structure) and [Notebook Structure](https://github.com/donnemartin/interactive-coding-challenges#notebook-structure) before submitting your pull request.**
The preferred way to contribute is to fork the
[main repository](https://github.com/donnemartin/interactive-coding-challenges) on GitHub.
1. Fork the [main repository](https://github.com/donnemartin/interactive-coding-challenges). Click on the 'Fork' button near the top of the page. This creates a copy of the code under your account on the GitHub server.
2. Clone this copy to your local disk:
$ git clone git@github.com:YourLogin/interactive-coding-challenges.git
$ cd interactive-coding-challenges
3. Create a branch to hold your changes and start making changes. Don't work in the ``master`` branch!
$ git checkout -b my-feature
4. Work on this copy on your computer using Git to do the version control. When you're done editing, run the following to record your changes in Git:
$ git add modified_files
$ git commit
5. Push your changes to GitHub with:
$ git push -u origin my-feature
6. Finally, go to the web page of your fork of the interactive-coding-challenges repo and click 'Pull request' to send your changes for review.
**Please submit one pull request per challenge.**
### GitHub Pull Requests Docs
If you are not familiar with pull requests, review the [pull request docs](https://help.github.com/articles/using-pull-requests/).
### Notebook Installation
Refer to [Accessing the Challenges](https://github.com/donnemartin/interactive-coding-challenges#accessing-the-challenges), [Notebook Installation](https://github.com/donnemartin/interactive-coding-challenges#notebook-installation), and [Nose Installation](https://github.com/donnemartin/interactive-coding-challenges#nose-installation) to set up your local environment.
### Adding New Solutions to Existing Challenges
Challenges have multiple solutions. If adding new solutions to existing challenges:
* Add your algorithm discussion and code solution to the existing notebook
* Update the unit test to include your solution
* Verify your code passes the unit tests
### Adding New Challenges
The README contains several sample challenges that are not yet implemented.
* The sample challenges are only suggestions, please do not limit yourself to only these topics
* Feel free to send pull requests on different challenges or categories of challenges
* Try to keep the "Challenge" title relatively short and expand on the details within the notebook
* Review the [Repo Structure](https://github.com/donnemartin/interactive-coding-challenges#repo-structure) and [Notebook Structure](https://github.com/donnemartin/interactive-coding-challenges#notebook-structure) sections
* Check out the [template challenge and solution notebooks](https://github.com/donnemartin/interactive-coding-challenges/tree/master/templates) to help you get started
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Check if a number is prime | [Contribute](https://github.com/donnemartin/interactive-coding-challenges#contributing)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges#contributing) |
| Generate a list of primes | [Contribute](https://github.com/donnemartin/interactive-coding-challenges#contributing)│[Contribute](https://github.com/donnemartin/interactive-coding-challenges#contributing) |
Update the list of challenges in the README so we can enjoy your challenge!
### Update Notebook Author(s)
When contributing to a notebook, update the notebook author(s):
<small><i>This notebook was prepared by [Joe](https://github.com/) and [Jane](https://github.com/). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges).</i></small>
### Maintain Consistent Style
Please refer to the style of existing notebooks to help maintain consistency. A consistently themed collection of notebooks will help users more seamlessly transition from challenge to challenge.
Review the following [style guide](https://google.github.io/styleguide/pyguide.html).
Review [PEP8](https://www.python.org/dev/peps/pep-0008/) and use a [validator](http://pep8online.com/).
*Note: IPython Notebook doesn't seem to properly handle a blank line at the end of a code cell when writing the cell's contents to a file, as referenced in this [issue](https://github.com/ipython/ipython/issues/8626). Notebook cells currently do not have a blank line at the end of each code cell.*
### Contributions in Languages Other than Python
Feel free to share your thoughts on how we could best approach adding challenges in other [supported languages](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages):
* Repo structure
* README challenge list
* Installation instructions
* Etc
Share your thoughts in this [issue](https://github.com/donnemartin/interactive-coding-challenges/issues/3).
================================================
FILE: LICENSE
================================================
I am providing code and resources in this repository to you under an open source
license. Because this is my personal repository, the license you receive to my
code and resources is from me and not my employer (Facebook).
Copyright 2015 Donne Martin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/cover_challenge.gif">
</p>
interactive-coding-challenges
============
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
**120+ continually updated, interactive, and test-driven coding challenges**, with [Anki flashcards](#anki-flashcards-coding-and-design).
Challenges focus on **algorithms** and **data structures** found in **coding interviews**.
Each challenge has one or more reference solutions that are:
* Fully functional
* Unit tested
* Easy-to-understand
Challenges will soon provide on-demand [incremental hints](https://github.com/donnemartin/interactive-coding-challenges/issues/22) to help you arrive at the optimal solution.
Notebooks also detail:
* Constraints
* Test cases
* Algorithms
* Big-O time and space complexities
Also included are **unit tested reference implementations** of various [data structures](#reference-implementations-data-structures) and [algorithms](#reference-implementations-algorithms).
## Challenge Solutions
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/cover_solution.gif">
</p>
<br/>
## Anki Flashcards: Coding and Design
<p align="center">
<img src="http://i.imgur.com/b4YtAEN.png">
<br/>
</p>
The provided [Anki flashcard deck](https://apps.ankiweb.net/) uses spaced repetition to help you retain key concepts.
* [Coding deck](anki_cards/Coding.apkg)
Great for use while on-the-go.
### Design Resource: The System Design Primer
Looking for resources to help you prep for the **System Design** and **Object-Oriented Design interviews**?
<p align="center">
<img src="http://i.imgur.com/zdCAkB3.png">
<br/>
</p>
Check out the sister repo [The System Design Primer](https://github.com/donnemartin/system-design-primer), which contains additional Anki decks:
* [System design deck](https://github.com/donnemartin/system-design-primer/blob/master/resources/flash_cards/System%20Design.apkg)
* [System design exercises deck](https://github.com/donnemartin/system-design-primer/blob/master/resources/flash_cards/System%20Design%20Exercises.apkg)
* [Object oriented design exercises deck](https://github.com/donnemartin/system-design-primer/blob/master/resources/flash_cards/OO%20Design.apkg)

## Notebook Structure
Each challenge has two notebooks, a **challenge notebook** with unit tests for you to solve and a **solution notebook** for reference.
### Problem Statement
* States the problem to solve.
### Constraints
* Describes any constraints or assumptions.
### Test Cases
* Describes the general and edge test cases that will be evaluated in the unit test.
### Algorithm
* [Challenge Notebook] Empty, refer to the solution notebook algorithm section if you need a hint.
* [Solution Notebook] One or more algorithm solution discussions, with Big-O time and space complexities.
### Hints
* [Challenge Notebook] Provides on-demand [incremental hints](https://github.com/donnemartin/interactive-coding-challenges/issues/22) to help you arrive at the optimal solution. Coming soon!
### Code (Challenge: Implement Me!)
* [Challenge Notebook] Skeleton code for you to implement.
* [Solution Notebook] One or more reference solutions.
### Unit Test
* [Challenge Notebook] Unit test for your code. Expected to fail until you solve the challenge.
* [Solution Notebook] Unit test for the reference solution(s).
## Index
### Challenges Categories
**Format**: Challenge Category - Number of Challenges
* [Arrays and Strings](#arrays-and-strings) - 10
* [Linked Lists](#linked-lists) - 8
* [Stacks and Queues](#stacks-and-queues) - 8
* [Graphs and Trees](#graphs-and-trees) - 21
* [Sorting](#sorting) - 10
* [Recursion and Dynamic Programming](#recursion-and-dynamic-programming) - 17
* [Mathematics and Probability](#mathematics-and-probability) - 6
* [Bit Manipulation](#bit-manipulation) - 8
* [Online Judges](#online-judges) - 16
* [System Design](https://github.com/donnemartin/system-design-primer#system-design-interview-questions-with-solutions) - 8
* [Object Oriented Design](https://github.com/donnemartin/system-design-primer#object-oriented-design-interview-questions-with-solutions) - 8
**Total number of challenges: 120**
### Reference Implementations: Data Structures
Unit tested, fully functional implementations of the following data structures:
* [Linked List](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/linked_list/linked_list_solution.ipynb)
* [Stack](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/stack/stack_solution.ipynb)
* [Queue](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/queue_list/queue_list_solution.ipynb)
* [Binary Search Tree](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst/bst_solution.ipynb)
* [Graph](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph/graph_solution.ipynb)
* [Min Heap](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/min_heap/min_heap_solution.ipynb)
* [Trie](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/trie/trie_solution.ipynb)
* [Priority Queue](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/priority_queue/priority_queue_solution.ipynb)
* [Hash Map](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/hash_map/hash_map_solution.ipynb)
### Reference Implementations: Algorithms
Unit tested, fully functional implementations of the following algorithms:
* [Selection Sort](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/selection_sort/selection_sort_solution.ipynb)
* [Insertion Sort](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/insertion_sort/insertion_sort_solution.ipynb)
* [Quick Sort](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/quick_sort/quick_sort_solution.ipynb)
* [Merge Sort](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/merge_sort/merge_sort_solution.ipynb)
* [Radix Sort](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/radix_sort/radix_sort_solution.ipynb)
* [Topological Sort](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_build_order/build_order_solution.ipynb)
* [Tree Depth-First Search (Pre-, In-, Post-Order)](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_dfs/dfs_solution.ipynb)
* [Tree Breadth-First Search](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_bfs/bfs_solution.ipynb)
* [Graph Depth-First Search](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_dfs/dfs_solution.ipynb)
* [Graph Breadth-First Search](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_bfs/bfs_solution.ipynb)
* [Dijkstra's Shortest Path](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_shortest_path/graph_shortest_path_solution.ipynb)
* [Unweighted Graph Shortest Path](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_shortest_path_unweighted/shortest_path_solution.ipynb)
* [Knapsack 0/1](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/knapsack_01/knapsack_solution.ipynb)
* [Knapsack Unbounded](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/knapsack_unbounded/knapsack_unbounded_solution.ipynb)
* [Sieve of Eratosthenes](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/generate_primes/check_prime_solution.ipynb)
### Reference Implementations: TODO
* [A*](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Bellman-Ford](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Bloom Filter](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Convex Hull](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Fisher-Yates Shuffle](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Kruskal's](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Max Flow](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Prim's](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Rabin-Karp](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Traveling Salesman](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Union Find](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
### Installing and Running Challenges
* [Repo Structure](#repo-structure)
* [Notebook Installation](#notebook-installation)
* [Running Challenges](#running-challenges)
### Misc
* [Contributing](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md)
* [Credits](#credits)
* [Contact Info](#contact-info)
* [License](#license)
## Challenges
[Image Credits](#credits)
<br/>
<p>
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/arrays_nltk.png">
</p>
<br/>
### Arrays and Strings
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebook |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Determine if a string contains unique characters | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/unique_chars/unique_chars_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/unique_chars/unique_chars_solution.ipynb) |
| Determine if a string is a permutation of another | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/permutation/permutation_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/permutation/permutation_solution.ipynb) |
| Determine if a string is a rotation of another | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/rotation/rotation_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/rotation/rotation_solution.ipynb) |
| Compress a string | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/compress/compress_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/compress/compress_solution.ipynb) |
| Reverse characters in a string | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/reverse_string/reverse_string_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/reverse_string/reverse_string_solution.ipynb) |
| Given two strings, find the single different char | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/str_diff/str_diff_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/str_diff/str_diff_solution.ipynb) |
| Find two indices that sum to a specific value | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/two_sum/two_sum_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/two_sum/two_sum_solution.ipynb) |
| Implement a hash table | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/hash_map/hash_map_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/hash_map/hash_map_solution.ipynb) |
| Implement fizz buzz | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/fizz_buzz/fizz_buzz_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb) |
| Find the first non-repeated character in a string | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Remove specified characters in a string | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Reverse words in a string | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Convert a string to an integer | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Convert an integer to a string | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/linked_lists_wikipedia.png">
</p>
<br/>
### Linked Lists
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebook |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Remove duplicates from a linked list | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/remove_duplicates/remove_duplicates_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/remove_duplicates/remove_duplicates_solution.ipynb) |
| Find the kth to last element of a linked list | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/kth_to_last_elem/kth_to_last_elem_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/kth_to_last_elem/kth_to_last_elem_solution.ipynb) |
| Delete a node in the middle of a linked list | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/delete_mid/delete_mid_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/delete_mid/delete_mid_solution.ipynb) |
| Partition a linked list around a given value | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/partition/partition_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/partition/partition_solution.ipynb) |
| Add two numbers whose digits are stored in a linked list | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/add_reverse/add_reverse_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/add_reverse/add_reverse_solution.ipynb) |
| Find the start of a linked list loop | [Challenge](http://nbviewer.jupyter.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/find_loop_start/find_loop_start_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/find_loop_start/find_loop_start_solution.ipynb) |
| Determine if a linked list is a palindrome | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/palindrome/palindrome_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/palindrome/palindrome_solution.ipynb) |
| Implement a linked list | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/linked_list/linked_list_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/linked_lists/linked_list/linked_list_solution.ipynb) |
| Determine if a list is cyclic or acyclic | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/stack_queue_wikipedia.png">
</p>
<br/>
### Stacks and Queues
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebook |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Implement n stacks using a single array | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/n_stacks/n_stacks_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/n_stacks/n_stacks_solution.ipynb) |
| Implement a stack that keeps track of its minimum element | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/stack_min/stack_min_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/stack_min/stack_min_solution.ipynb) |
| Implement a set of stacks class that wraps a list of capacity-bounded stacks | [Challenge](http://nbviewer.jupyter.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/set_of_stacks/set_of_stacks_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb) |
| Implement a queue using two stacks | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/queue_from_stacks/queue_from_stacks_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/queue_from_stacks/queue_from_stacks_solution.ipynb) |
| Sort a stack using another stack as a buffer | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/sort_stack/sort_stack_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/sort_stack/sort_stack_solution.ipynb) |
| Implement a stack | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/stack/stack_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/stack/stack_solution.ipynb) |
| Implement a queue | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/queue_list/queue_list_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/stacks_queues/queue_list/queue_list_solution.ipynb) |
| Implement a priority queue backed by an array | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/priority_queue/priority_queue_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/priority_queue/priority_queue_solution.ipynb) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/binary_tree_wikipedia.png">
</p>
<br/>
### Graphs and Trees
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Implement depth-first search (pre-, in-, post-order) on a tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_dfs/dfs_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_dfs/dfs_solution.ipynb) |
| Implement breadth-first search on a tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_bfs/bfs_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_bfs/bfs_solution.ipynb) |
| Determine the height of a tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_height/height_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_height/height_solution.ipynb) |
| Create a binary search tree with minimal height from a sorted array | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_min/bst_min_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_min/bst_min_solution.ipynb) |
| Create a linked list for each level of a binary tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_level_lists/tree_level_lists_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_level_lists/tree_level_lists_solution.ipynb) |
| Check if a binary tree is balanced | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/check_balance/check_balance_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/check_balance/check_balance_solution.ipynb) |
| Determine if a tree is a valid binary search tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_validate/bst_validate_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_validate/bst_validate_solution.ipynb) |
| Find the in-order successor of a given node in a binary search tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_successor/bst_successor_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_successor/bst_successor_solution.ipynb) |
| Find the second largest node in a binary search tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_second_largest/bst_second_largest_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst_second_largest/bst_second_largest_solution.ipynb) |
| Find the lowest common ancestor | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_lca/tree_lca_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/tree_lca/tree_lca_solution.ipynb) |
| Invert a binary tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/invert_tree/invert_tree_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/invert_tree/invert_tree_solution.ipynb) |
| Implement a binary search tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst/bst_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/bst/bst_solution.ipynb) |
| Implement a min heap | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/min_heap/min_heap_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/min_heap/min_heap_solution.ipynb) |
| Implement a trie | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/trie/trie_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/trie/trie_solution.ipynb) |
| Implement depth-first search on a graph | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_dfs/dfs_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_dfs/dfs_solution.ipynb) |
| Implement breadth-first search on a graph | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_bfs/bfs_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_bfs/bfs_solution.ipynb) |
| Determine if there is a path between two nodes in a graph | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_path_exists/path_exists_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_path_exists/path_exists_solution.ipynb) |
| Implement a graph | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph/graph_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph/graph_solution.ipynb) |
| Find a build order given a list of projects and dependencies. | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_build_order/build_order_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_build_order/build_order_solution.ipynb) |
| Find the shortest path in a weighted graph. | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_shortest_path/graph_shortest_path_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_shortest_path/graph_shortest_path_solution.ipynb) |
| Find the shortest path in an unweighted graph. | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_shortest_path_unweighted/shortest_path_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/graphs_trees/graph_shortest_path_unweighted/shortest_path_solution.ipynb) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif">
</p>
<br/>
### Sorting
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Implement selection sort | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/selection_sort/selection_sort_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/selection_sort/selection_sort_solution.ipynb) |
| Implement insertion sort | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/insertion_sort/insertion_sort_solution.ipynb) |
| Implement quick sort | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/quick_sort/quick_sort_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/quick_sort/quick_sort_solution.ipynb) |
| Implement merge sort | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/merge_sort/merge_sort_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/merge_sort/merge_sort_solution.ipynb) |
| Implement radix sort | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/radix_sort/radix_sort_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/radix_sort/radix_sort_solution.ipynb) |
| Sort an array of strings so all anagrams are next to each other | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/anagrams/anagrams_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/anagrams/anagrams_solution.ipynb) |
| Find an item in a sorted, rotated array | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/rotated_array_search/rotated_array_search_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/rotated_array_search/rotated_array_search_solution.ipynb) |
| Search a sorted matrix for an item | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/search_sorted_matrix/search_sorted_matrix_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/search_sorted_matrix/search_sorted_matrix_solution.ipynb) |
| Find an int not in an input of n integers | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/new_int/new_int_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/new_int/new_int_solution.ipynb) |
| Given sorted arrays A, B, merge B into A in sorted order | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/merge_into/merge_into_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/sorting_searching/merge_into/merge_into_solution.ipynb) |
| Implement a stable selection sort | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Make an unstable sort stable | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Implement an efficient, in-place version of quicksort | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Given two sorted arrays, merge one into the other in sorted order | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Find an element in a rotated and sorted array of integers | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/fibonacci_wikipedia.png">
</p>
<br/>
### Recursion and Dynamic Programming
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Implement fibonacci recursively, dynamically, and iteratively | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/fibonacci/fibonacci_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/fibonacci/fibonacci_solution.ipynb) |
| Maximize items placed in a knapsack | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/knapsack_01/knapsack_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/knapsack_01/knapsack_solution.ipynb) |
| Maximize unbounded items placed in a knapsack | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/knapsack_unbounded/knapsack_unbounded_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/knapsack_unbounded/knapsack_unbounded_solution.ipynb) |
| Find the longest common subsequence | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/longest_common_subsequence/longest_common_subseq_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/longest_common_subsequence/longest_common_subseq_solution.ipynb) |
| Find the longest increasing subsequence | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/longest_inc_subseq/longest_inc_subseq_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/longest_inc_subseq/longest_inc_subseq_solution.ipynb) |
| Minimize the cost of matrix multiplication | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/matrix_mult/find_min_cost_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/matrix_mult/find_min_cost_solution.ipynb) |
| Maximize stock prices given k transactions | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/max_profit_k/max_profit_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/max_profit_k/max_profit_solution.ipynb) |
| Find the minimum number of ways to represent n cents given an array of coins | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change_min/coin_change_min_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change_min/coin_change_min_solution.ipynb) |
| Find the unique number of ways to represent n cents given an array of coins | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change/coin_change_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/coin_change/coin_change_solution.ipynb) |
| Print all valid combinations of n-pairs of parentheses | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/n_pairs_parentheses/n_pairs_parentheses_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/n_pairs_parentheses/n_pairs_parentheses_solution.ipynb) |
| Navigate a maze | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/grid_path/grid_path_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/grid_path/grid_path_solution.ipynb) |
| Print all subsets of a set | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/power_set/power_set_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/power_set/power_set_solution.ipynb) |
| Print all permutations of a string | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/permutations/permutations_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/permutations/permutations_solution.ipynb) |
| Find the magic index in an array | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/magic_index/magic_index_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/magic_index/magic_index_solution.ipynb) |
| Find the number of ways to run up n steps | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/steps/steps_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/steps/steps_solution.ipynb) |
| Implement the Towers of Hanoi with 3 towers and N disks | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/hanoi/hanoi_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/recursion_dynamic/hanoi/hanoi_solution.ipynb) |
| Implement factorial recursively, dynamically, and iteratively | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Perform a binary search on a sorted array of integers | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Print all combinations of a string | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Implement a paint fill function | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Find all permutations to represent n cents, given 1, 5, 10, 25 cent coins | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/probability_distribution_wikipedia.png">
</p>
<br/>
### Mathematics and Probability
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Generate a list of primes | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/generate_primes/check_prime_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/generate_primes/check_prime_solution.ipynb) |
| Find the digital root | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/add_digits/add_digits_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/add_digits/add_digits_solution.ipynb) |
| Create a class supporting insert, max, min, mean, mode in O(1) | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/math_ops/math_ops_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/math_ops/math_ops_solution.ipynb) |
| Determine if a number is a power of two | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/power_two/power_two_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/power_two/power_two_solution.ipynb) |
| Add two numbers without the + or - sign | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/sum_two/sum_two_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/sum_two/sum_two_solution.ipynb) |
| Subtract two numbers without the + or - sign | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/sub_two/sub_two_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/math_probability/sub_two/sub_two_solution.ipynb) |
| Check if a number is prime | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Determine if two lines on a Cartesian plane intersect | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Using only add, implement multiply, subtract, and divide for ints | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Find the kth number such that the only prime factors are 3, 5, and 7 | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/bit_manipulation_wikipedia.png">
</p>
<br/>
### Bit Manipulation
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Implement common bit manipulation operations | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/bit/bit_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/bit/bit_solution.ipynb) |
| Determine number of bits to flip to convert a into b | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/bits_to_flip/bits_to_flip_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/bits_to_flip/bits_to_flip_solution.ipynb) |
| Draw a line on a screen | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/draw_line/draw_line_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/draw_line/draw_line_solution.ipynb) |
| Flip a bit to maximize the longest sequence of 1s | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/flip_bit/flip_bit_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/flip_bit/flip_bit_solution.ipynb) |
| Get the next largest and next smallest numbers | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/get_next/get_next_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/get_next/get_next_solution.ipynb) |
| Merge two binary numbers | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/insert_m_into_n/insert_m_into_n_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/insert_m_into_n/insert_m_into_n_solution.ipynb) |
| Swap odd and even bits in an integer | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/pairwise_swap/pairwise_swap_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/pairwise_swap/pairwise_swap_solution.ipynb) |
| Print the binary representation of a number between 0 and 1 | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/print_binary/print_binary_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/bit_manipulation/print_binary/print_binary_solution.ipynb) |
| Determine the number of 1s in the binary representation of a given integer | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/images/logo_topcoder.png">
</p>
<br/>
### Online Judges
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
| Challenge | Static Notebooks |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| Find the longest substring with at most k distinct chars | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/longest_substr_k_distinct/longest_substr_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/longest_substr_k_distinct/longest_substr_solution.ipynb) |
| Find the highest product of three numbers | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/prod_three/prod_three_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/prod_three/prod_three_solution.ipynb) |
| Maximize stocks profit from 1 buy and 1 sell | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/max_profit/max_profit_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/max_profit/max_profit_solution.ipynb) |
| Move all zeroes in a list to the end | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/move_zeroes/move_zeroes_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/move_zeroes/move_zeroes_solution.ipynb) |
| Find the products of every other int | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/mult_other_numbers/mult_other_numbers_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/mult_other_numbers/mult_other_numbers_solution.ipynb) |
| Given a list of entries and exits, find the busiest period | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/busiest_period/busiest_period_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/busiest_period/busiest_period_solution.ipynb) |
| Determine an island's perimeter | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/island_perimeter/island_perimeter_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/island_perimeter/island_perimeter_solution.ipynb) |
| Format license keys | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/license_key/format_license_key_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/license_key/format_license_key_solution.ipynb) |
| Find the longest absolute file path | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/longest_abs_file_path/longest_path_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/longest_abs_file_path/longest_path_solution.ipynb) |
| Merge tuple ranges | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/merge_ranges/merge_ranges_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/merge_ranges/merge_ranges_solution.ipynb) |
| Assign cookies | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/assign_cookies/assign_cookies_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/assign_cookies/assign_cookies_solution.ipynb) |
| Determine if you can win in Nim | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/nim/nim_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/nim/nim_solution.ipynb) |
| Check if a magazine could have been used to create a ransom note | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/ransom_note/ransom_note_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/ransom_note/ransom_note_solution.ipynb) |
| Find the number of times a sentence can fit on a screen | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/sentence_screen_fit/sentence_screen_fit_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/sentence_screen_fit/sentence_screen_fit_solution.ipynb) |
| Utopian tree | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/utopian_tree/utopian_tree_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/utopian_tree/utopian_tree_solution.ipynb) |
| Maximizing xor | [Challenge](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/maximizing_xor/maximizing_xor_challenge.ipynb) │ [Solution](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/online_judges/maximizing_xor/maximizing_xor_solution.ipynb) |
| Add a challenge | [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) │ [Contribute](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) |
## Repo Structure
```
interactive-coding-challenges # Repo
├─ arrays_strings # Category of challenges
│ ├─ rotation # Challenge folder
│ │ ├─ rotation_challenge.ipynb # Challenge notebook
│ │ ├─ rotation_solution.ipynb # Solution notebook
│ │ ├─ test_rotation.py # Unit test*
│ ├─ compress
│ │ ├─ compress_challenge.ipynb
│ │ ├─ compress_solution.ipynb
│ │ ├─ test_compress.py
│ ├─ ...
├─ linked_lists
│ ├─ palindrome
│ │ └─ ...
│ ├─ ...
├─ ...
```
<i>\*The notebooks (.ipynb) read/write the associated unit test (.py) file.</i>
## Notebook Installation
### Zero Install
[](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master)
This README contains links to [Binder](https://mybinder.org/v2/gh/donnemartin/interactive-coding-challenges/master) , which hosts **dynamic notebooks** of the repo's contents online with no installation needed.
### Jupyter Notebook
Run:
```
pip install jupyter
```
For detailed instructions, scripts, and tools to more optimally set up your development environment, check out the [dev-setup](https://github.com/donnemartin/dev-setup) repo.
For more details on notebook installation, follow the directions [here](http://ipython.org/install.html).
More information on IPython/Jupyter Notebooks can be found [here](http://ipython.org/notebook.html).
## Running Challenges
### Notebooks
Challenges are provided in the form of **IPython/Jupyter Notebooks** and have been **tested with Python 2.7 and Python 3.x**.
*If you need to install IPython/Jupyter Notebook, see the [Notebook Installation](#notebook-installation) section.*
* This README contains links to [nbviewer](http://nbviewer.ipython.org), which hosts **static notebooks** of the repo's contents
* To interact with or to modify elements within the **dynamic notebooks**, refer to the instructions below
Run the notebook of challenges:
```
$ git clone https://github.com/donnemartin/interactive-coding-challenges.git
$ cd interactive-coding-challenges
$ jupyter notebook
```
This will launch your web browser with the list of challenge categories:
* Navigate to the **Challenge Notebook** you wish to solve
* Run the cells within the challenge notebook (Cell->Run All)
* This will result in an expected unit test error
* Solve the challenge and verify it passes the unit test
* Check out the accompanying **Solution Notebook** for further discussion
To **debug** your solution with pdb, refer to the following [ticket](https://github.com/donnemartin/interactive-coding-challenges/issues/11).
Note: If your solution is different from those listed in the Solution Notebook, consider submitting a pull request so others can benefit from your work. Review the [Contributing Guidelines](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) for details.
## Future Development
Challenges, solutions, and unit tests are presented in the form of **IPython/Jupyter Notebooks**.
* Notebooks currently contain mostly Python solutions (tested on both Python 2.7 and Python 3.x), but can be extended to include [40+ supported languages](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages)
* Repo will be **continually updated** with new solutions and challenges
* [Contributions](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) are welcome!
## Contributing
Contributions are welcome!
Review the [Contributing Guidelines](https://github.com/donnemartin/interactive-coding-challenges/blob/master/CONTRIBUTING.md) for details on how to:
* Submit issues
* Add solutions to existing challenges
* Add new challenges
## Credits
### Resources
* [Cracking the Coding Interview](http://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/098478280X) | [GitHub Solutions](https://github.com/gaylemcd/ctci)
* [Programming Interviews Exposed](http://www.amazon.com/gp/product/1118261364/)
* [The Algorithm Design Manual](http://www.amazon.com/Algorithm-Design-Manual-Steve-Skiena/dp/0387948600) | [Solutions](http://www.algorithm.cs.sunysb.edu/algowiki/index.php/The_Algorithms_Design_Manual_(Second_Edition))
* [CareerCup](http://www.careercup.com/)
* [Quora](http://www.quora.com/)
* [HackerRank](https://www.hackerrank.com)
* [LeetCode](https://leetcode.com/)
### Images
* [Arrays and Strings: nltk.org](http://www.nltk.org/images/string-slicing.png)
* [Linked Lists: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/6/6d/Singly-linked-list.svg)
* [Stacks: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/2/29/Data_stack.svg)
* [Queues: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/5/52/Data_Queue.svg)
* [Sorting: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif)
* [Recursion and Dynamic Programming: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/b/bf/PascalTriangleFibanacci.svg)
* [Graphs and Trees: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/f/f7/Binary_tree.svg)
* [Mathematics and Probability: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/d/d2/Gaussian_distribution_2.jpg)
* [Bit Manipulation: wikipedia.org](https://upload.wikimedia.org/wikipedia/commons/5/5c/Rotate_left_logically.svg)
* [Online Judges: topcoder.com](https://www.topcoder.com/wp-content/uploads/2014/05/topcoder_logo_home_sm.png)
## Contact Info
Feel free to contact me to discuss any issues, questions, or comments.
My contact info can be found on my [GitHub page](https://github.com/donnemartin).
## License
*I am providing code and resources in this repository to you under an open source license. Because this is my personal repository, the license you receive to my code and resources is from me and not my employer (Facebook).*
Copyright 2015 Donne Martin
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: __init__.py
================================================
================================================
FILE: arrays_strings/__init__.py
================================================
================================================
FILE: arrays_strings/compress/__init__.py
================================================
================================================
FILE: arrays_strings/compress/compress_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Compress a string such that 'AAABCCDDDD' becomes 'A3BC2D4'. Only compress the string if it saves space.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is this case sensitive?\n",
" * Yes\n",
"* Can we use additional data structures? \n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None -> None\n",
"* '' -> ''\n",
"* 'AABBCC' -> 'AABBCC'\n",
"* 'AAABCCDDDD' -> 'A3BC2D4'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/compress/compress_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class CompressString(object):\n",
"\n",
" def compress(self, string):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_compress.py\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
" print('Success: test_compress')\n",
"\n",
"\n",
"def main():\n",
" test = TestCompress()\n",
" compress_string = CompressString()\n",
" test.test_compress(compress_string.compress)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/compress/compress_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/compress/compress_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Compress a string such that 'AAABCCDDDD' becomes 'A3BC2D4'. Only compress the string if it saves space.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is this case sensitive?\n",
" * Yes\n",
"* Can we use additional data structures? \n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None -> None\n",
"* '' -> ''\n",
"* 'AABBCC' -> 'AABBCC'\n",
"* 'AAABCCDDDD' -> 'A3BC2D4'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"* For each char in string\n",
" * If char is the same as last_char, increment count\n",
" * Else\n",
" * Append last_char and count to compressed_string\n",
" * last_char = char\n",
" * count = 1\n",
"* Append last_char and count to compressed_string\n",
"* If the compressed string size is < string size\n",
" * Return compressed string\n",
"* Else\n",
" * Return string\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(n)\n",
"\n",
"Complexity Note:\n",
"* Although strings are immutable in Python, appending to strings is optimized in CPython so that it now runs in O(n) and extends the string in-place. Refer to this [Stack Overflow post](http://stackoverflow.com/a/4435752)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"class CompressString(object):\n",
"\n",
" def compress(self, string):\n",
" if string is None or not string:\n",
" return string\n",
" result = ''\n",
" prev_char = string[0]\n",
" count = 0\n",
" for char in string:\n",
" if char == prev_char:\n",
" count += 1\n",
" else:\n",
" result += self._calc_partial_result(prev_char, count)\n",
" prev_char = char\n",
" count = 1\n",
" result += self._calc_partial_result(prev_char, count)\n",
" return result if len(result) < len(string) else string\n",
"\n",
" def _calc_partial_result(self, prev_char, count):\n",
" return prev_char + (str(count) if count > 1 else '')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_compress.py\n"
]
}
],
"source": [
"%%writefile test_compress.py\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')\n",
" self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')\n",
" self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')\n",
" print('Success: test_compress')\n",
"\n",
"\n",
"def main():\n",
" test = TestCompress()\n",
" compress_string = CompressString()\n",
" test.test_compress(compress_string.compress)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_compress\n"
]
}
],
"source": [
"%run -i test_compress.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/compress/test_compress.py
================================================
import unittest
class TestCompress(unittest.TestCase):
def test_compress(self, func):
self.assertEqual(func(None), None)
self.assertEqual(func(''), '')
self.assertEqual(func('AABBCC'), 'AABBCC')
self.assertEqual(func('AAABCCDDDDE'), 'A3BC2D4E')
self.assertEqual(func('BAAACCDDDD'), 'BA3C2D4')
self.assertEqual(func('AAABAACCDDDD'), 'A3BA2C2D4')
print('Success: test_compress')
def main():
test = TestCompress()
compress_string = CompressString()
test.test_compress(compress_string.compress)
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/compress_alt/__init__.py
================================================
================================================
FILE: arrays_strings/compress_alt/better_compress_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [hashhar](https://github.com/hashhar). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Compress a string such that 'AAABCCDDDD' becomes 'A3BCCD4'. Only compress the string if it saves space.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is this case sensitive?\n",
" * Yes\n",
"* Can we use additional data structures? \n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None -> None\n",
"* '' -> ''\n",
"* 'AABBCC' -> 'AABBCC'\n",
"* 'AAABCCDDDD' -> 'A3BCCD4'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/compress_alt/better_compress_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def compress_string(string):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_compress.py\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
" self.assertEqual(\n",
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
" )\n",
" print('Success: test_compress')\n",
"\n",
"\n",
"def main():\n",
" test = TestCompress()\n",
" test.test_compress(compress_string)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/compress_alt/better_compress_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/compress_alt/better_compress_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [hashhar](https://github.com/hashhar), second solution added by [janhak](https://github.com/janhak). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Compress a string such that 'AAABCCDDDD' becomes 'A3BCCD4'. Only compress the string if it saves space.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is this case sensitive?\n",
" * Yes\n",
"* Can we use additional data structures? \n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None -> None\n",
"* '' -> ''\n",
"* 'AABBCC' -> 'AABBCC'\n",
"* 'AAABCCDDDD' -> 'A3BCCD4'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Since Python strings are immutable, we'll use a list of characters to build the compressed string representation. We'll then convert the list to a string.\n",
"\n",
"* Calculate the size of the compressed string\n",
" * Note the constraint about compressing only if it saves space\n",
"* If the compressed string size is >= string size, return string\n",
"* Create compressed_string\n",
" * For each char in string\n",
" * If char is the same as last_char, increment count\n",
" * Else\n",
" * If the count is more than 2\n",
" * Append last_char to compressed_string\n",
" * append count to compressed_string\n",
" * count = 1\n",
" * last_char = char\n",
" * If count is 1\n",
" * Append last_char to compressed_string\n",
" * count = 1\n",
" * last_char = char\n",
" * If count is 2\n",
" * Append last_char to compressed_string\n",
" * Append last_char to compressed_string once more\n",
" * count = 1\n",
" * last_char = char\n",
" * Append last_char to compressed_string\n",
" * Append count to compressed_string\n",
" * Return compressed_string\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def compress_string(string):\n",
" if string is None or len(string) == 0:\n",
" return string\n",
"\n",
" # Calculate the size of the compressed string\n",
" size = 0\n",
" last_char = string[0]\n",
" for char in string:\n",
" if char != last_char:\n",
" size += 2\n",
" last_char = char\n",
" size += 2\n",
"\n",
" # If the compressed string size is greater than\n",
" # or equal to string size, return original string\n",
" if size >= len(string):\n",
" return string\n",
"\n",
" # Create compressed_string\n",
" # New objective:\n",
" # Single characters are to be left as is\n",
" # Double characters are to be left as are\n",
" compressed_string = list()\n",
" count = 0\n",
" last_char = string[0]\n",
" for char in string:\n",
" if char == last_char:\n",
" count += 1\n",
" else:\n",
" # Do the old compression tricks only if count exceeds two\n",
" if count > 2:\n",
" compressed_string.append(last_char)\n",
" compressed_string.append(str(count))\n",
" count = 1\n",
" last_char = char\n",
" # If count is either 1 or 2\n",
" else:\n",
" # If count is 1, leave the char as is\n",
" if count == 1:\n",
" compressed_string.append(last_char)\n",
" count = 1\n",
" last_char = char\n",
" # If count is 2, append the character twice\n",
" else:\n",
" compressed_string.append(last_char)\n",
" compressed_string.append(last_char)\n",
" count = 1\n",
" last_char = char\n",
" compressed_string.append(last_char)\n",
" compressed_string.append(str(count))\n",
"\n",
" # Convert the characters in the list to a string\n",
" return \"\".join(compressed_string)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm: Split to blocks and compress\n",
"\n",
"Let us split the string first into blocks of identical characters and then compress it block by block.\n",
"\n",
"* Split the string to blocks\n",
" * For each character in string\n",
" * Add this character to block\n",
" * If the next character is different\n",
" * Return block\n",
" * Erase the content of block\n",
"\n",
"\n",
"* Compress block\n",
" * If block consists of two or fewer characters\n",
" * Return block\n",
" * Else\n",
" * Append length of the block to the first character and return\n",
"\n",
"\n",
"* Compress string\n",
" * Split the string to blocks\n",
" * Compress blocks\n",
" * Join compressed blocks\n",
" * Return result if it is shorter than original string\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(n)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def split_to_blocks(string):\n",
" block = ''\n",
" for char, next_char in zip(string, string[1:] + ' '):\n",
" block += char\n",
" if char is not next_char:\n",
" yield block\n",
" block = ''\n",
"\n",
"\n",
"def compress_block(block):\n",
" if len(block) <= 2:\n",
" return block\n",
" else:\n",
" return block[0] + str(len(block))\n",
"\n",
"\n",
"def compress_string(string):\n",
" if string is None or not string:\n",
" return string\n",
" compressed = (compress_block(block) for block in split_to_blocks(string))\n",
" result = ''.join(compressed)\n",
" return result if len(result) < len(string) else string"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_compress.py\n"
]
}
],
"source": [
"%%writefile test_compress.py\n",
"import unittest\n",
"\n",
"\n",
"class TestCompress(unittest.TestCase):\n",
"\n",
" def test_compress(self, func):\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(''), '')\n",
" self.assertEqual(func('AABBCC'), 'AABBCC')\n",
" self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')\n",
" self.assertEqual(\n",
" func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),\n",
" 'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',\n",
" )\n",
" print('Success: test_compress')\n",
"\n",
"\n",
"def main():\n",
" test = TestCompress()\n",
" test.test_compress(compress_string)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_compress\n"
]
}
],
"source": [
"%run -i test_compress.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/compress_alt/test_compress.py
================================================
import unittest
class TestCompress(unittest.TestCase):
def test_compress(self, func):
self.assertEqual(func(None), None)
self.assertEqual(func(''), '')
self.assertEqual(func('AABBCC'), 'AABBCC')
self.assertEqual(func('AAABCCDDDD'), 'A3BCCD4')
self.assertEqual(
func('aaBCCEFFFFKKMMMMMMP taaammanlaarrrr seeeeeeeeek tooo'),
'aaBCCEF4KKM6P ta3mmanlaar4 se9k to3',
)
print('Success: test_compress')
def main():
test = TestCompress()
test.test_compress(compress_string)
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/fizz_buzz/__init__.py
================================================
================================================
FILE: arrays_strings/fizz_buzz/fizz_buzz_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement Fizz Buzz.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* What is fizz buzz?\n",
" * Return the string representation of numbers from 1 to n\n",
" * Multiples of 3 -> 'Fizz'\n",
" * Multiples of 5 -> 'Buzz'\n",
" * Multiples of 3 and 5 -> 'FizzBuzz'\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"<pre>\n",
"* None -> Exception\n",
"* < 1 -> Exception\n",
"* 15 ->\n",
"[\n",
" '1',\n",
" '2',\n",
" 'Fizz',\n",
" '4',\n",
" 'Buzz',\n",
" 'Fizz',\n",
" '7',\n",
" '8',\n",
" 'Fizz',\n",
" 'Buzz',\n",
" '11',\n",
" 'Fizz',\n",
" '13',\n",
" '14',\n",
" 'FizzBuzz'\n",
"]\n",
"</pre>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
"\n",
" def fizz_buzz(self, num):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_fizz_buzz.py\n",
"import unittest\n",
"\n",
"\n",
"class TestFizzBuzz(unittest.TestCase):\n",
"\n",
" def test_fizz_buzz(self):\n",
" solution = Solution()\n",
" self.assertRaises(TypeError, solution.fizz_buzz, None)\n",
" self.assertRaises(ValueError, solution.fizz_buzz, 0)\n",
" expected = [\n",
" '1',\n",
" '2',\n",
" 'Fizz',\n",
" '4',\n",
" 'Buzz',\n",
" 'Fizz',\n",
" '7',\n",
" '8',\n",
" 'Fizz',\n",
" 'Buzz',\n",
" '11',\n",
" 'Fizz',\n",
" '13',\n",
" '14',\n",
" 'FizzBuzz'\n",
" ]\n",
" self.assertEqual(solution.fizz_buzz(15), expected)\n",
" print('Success: test_fizz_buzz')\n",
"\n",
"\n",
"def main():\n",
" test = TestFizzBuzz()\n",
" test.test_fizz_buzz()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement Fizz Buzz.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* What is fizz buzz?\n",
" * Return the string representation of numbers from 1 to n\n",
" * Multiples of 3 -> 'Fizz'\n",
" * Multiples of 5 -> 'Buzz'\n",
" * Multiples of 3 and 5 -> 'FizzBuzz'\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"<pre>\n",
"* None -> Exception\n",
"* < 1 -> Exception\n",
"* 15 ->\n",
"[\n",
" '1',\n",
" '2',\n",
" 'Fizz',\n",
" '4',\n",
" 'Buzz',\n",
" 'Fizz',\n",
" '7',\n",
" '8',\n",
" 'Fizz',\n",
" 'Buzz',\n",
" '11',\n",
" 'Fizz',\n",
" '13',\n",
" '14',\n",
" 'FizzBuzz'\n",
"]\n",
"</pre>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"There is no fancy algorithm to solve fizz buzz.\n",
"\n",
"* Iterate from 1 through n\n",
"* Use the mod operator to determine if the current iteration is divisible by:\n",
" * 3 and 5 -> 'FizzBuzz'\n",
" * 3 -> 'Fizz'\n",
" * 5 -> 'Buzz'\n",
" * else -> string of current iteration\n",
"* return the results\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
"\n",
" def fizz_buzz(self, num):\n",
" if num is None:\n",
" raise TypeError('num cannot be None')\n",
" if num < 1:\n",
" raise ValueError('num cannot be less than one')\n",
" results = []\n",
" for i in range(1, num + 1):\n",
" if i % 3 == 0 and i % 5 == 0:\n",
" results.append('FizzBuzz')\n",
" elif i % 3 == 0:\n",
" results.append('Fizz')\n",
" elif i % 5 == 0:\n",
" results.append('Buzz')\n",
" else:\n",
" results.append(str(i))\n",
" return results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_fizz_buzz.py\n"
]
}
],
"source": [
"%%writefile test_fizz_buzz.py\n",
"import unittest\n",
"\n",
"\n",
"class TestFizzBuzz(unittest.TestCase):\n",
"\n",
" def test_fizz_buzz(self):\n",
" solution = Solution()\n",
" self.assertRaises(TypeError, solution.fizz_buzz, None)\n",
" self.assertRaises(ValueError, solution.fizz_buzz, 0)\n",
" expected = [\n",
" '1',\n",
" '2',\n",
" 'Fizz',\n",
" '4',\n",
" 'Buzz',\n",
" 'Fizz',\n",
" '7',\n",
" '8',\n",
" 'Fizz',\n",
" 'Buzz',\n",
" '11',\n",
" 'Fizz',\n",
" '13',\n",
" '14',\n",
" 'FizzBuzz'\n",
" ]\n",
" self.assertEqual(solution.fizz_buzz(15), expected)\n",
" print('Success: test_fizz_buzz')\n",
"\n",
"\n",
"def main():\n",
" test = TestFizzBuzz()\n",
" test.test_fizz_buzz()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_fizz_buzz\n"
]
}
],
"source": [
"%run -i test_fizz_buzz.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/fizz_buzz/test_fizz_buzz.py
================================================
import unittest
class TestFizzBuzz(unittest.TestCase):
def test_fizz_buzz(self):
solution = Solution()
self.assertRaises(TypeError, solution.fizz_buzz, None)
self.assertRaises(ValueError, solution.fizz_buzz, 0)
expected = [
'1',
'2',
'Fizz',
'4',
'Buzz',
'Fizz',
'7',
'8',
'Fizz',
'Buzz',
'11',
'Fizz',
'13',
'14',
'FizzBuzz'
]
self.assertEqual(solution.fizz_buzz(15), expected)
print('Success: test_fizz_buzz')
def main():
test = TestFizzBuzz()
test.test_fizz_buzz()
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/hash_map/__init__.py
================================================
================================================
FILE: arrays_strings/hash_map/hash_map_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement a hash table with set, get, and remove methods.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* For simplicity, are the keys integers only?\n",
" * Yes\n",
"* For collision resolution, can we use chaining?\n",
" * Yes\n",
"* Do we have to worry about load factors?\n",
" * No\n",
"* Do we have to validate inputs?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* `get` no matching key -> KeyError exception\n",
"* `get` matching key -> value\n",
"* `set` no matching key -> new key, value\n",
"* `set` matching key -> update value\n",
"* `remove` no matching key -> KeyError exception\n",
"* `remove` matching key -> remove key, value"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/hash_map/hash_map_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Item(object):\n",
"\n",
" def __init__(self, key, value):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
"\n",
"class HashTable(object):\n",
"\n",
" def __init__(self, size):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def _hash_function(self, key):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def set(self, key, value):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def get(self, key):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def remove(self, key):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_hash_map.py\n",
"import unittest\n",
"\n",
"\n",
"class TestHashMap(unittest.TestCase):\n",
"\n",
" # TODO: It would be better if we had unit tests for each\n",
" # method in addition to the following end-to-end test\n",
" def test_end_to_end(self):\n",
" hash_table = HashTable(10)\n",
"\n",
" print(\"Test: get on an empty hash table index\")\n",
" self.assertRaises(KeyError, hash_table.get, 0)\n",
"\n",
" print(\"Test: set on an empty hash table index\")\n",
" hash_table.set(0, 'foo')\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" hash_table.set(1, 'bar')\n",
" self.assertEqual(hash_table.get(1), 'bar')\n",
"\n",
" print(\"Test: set on a non empty hash table index\")\n",
" hash_table.set(10, 'foo2')\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo2')\n",
"\n",
" print(\"Test: set on a key that already exists\")\n",
" hash_table.set(10, 'foo3')\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo3')\n",
"\n",
" print(\"Test: remove on a key that already exists\")\n",
" hash_table.remove(10)\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertRaises(KeyError, hash_table.get, 10)\n",
"\n",
" print(\"Test: remove on a key that doesn't exist\")\n",
" self.assertRaises(KeyError, hash_table.remove, -1)\n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestHashMap()\n",
" test.test_end_to_end()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/hash_map/hash_map_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/hash_map/hash_map_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement a hash table with set, get, and remove methods.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* For simplicity, are the keys integers only?\n",
" * Yes\n",
"* For collision resolution, can we use chaining?\n",
" * Yes\n",
"* Do we have to worry about load factors?\n",
" * No\n",
"* Do we have to validate inputs?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* `get` no matching key -> KeyError exception\n",
"* `get` matching key -> value\n",
"* `set` no matching key -> new key, value\n",
"* `set` matching key -> update value\n",
"* `remove` no matching key -> KeyError exception\n",
"* `remove` matching key -> remove key, value"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"### Hash Function\n",
"\n",
"* Return key % table size\n",
"\n",
"Complexity:\n",
"* Time: O(1)\n",
"* Space: O(1)\n",
"\n",
"### Set\n",
"\n",
"* Get hash index for lookup\n",
"* If key exists, replace\n",
"* Else, add\n",
"\n",
"Complexity:\n",
"* Time: O(1) average and best, O(n) worst\n",
"* Space: O(1) space for newly added element\n",
"\n",
"### Get\n",
"\n",
"* Get hash index for lookup\n",
"* If key exists, return value\n",
"* Else, raise KeyError\n",
"\n",
"Complexity:\n",
"* Time: O(1) average and best, O(n) worst\n",
"* Space: O(1)\n",
"\n",
"### Remove\n",
"\n",
"* Get hash index for lookup\n",
"* If key exists, delete the item\n",
"* Else, raise KeyError\n",
"\n",
"Complexity:\n",
"* Time: O(1) average and best, O(n) worst\n",
"* Space: O(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"class Item(object):\n",
"\n",
" def __init__(self, key, value):\n",
" self.key = key\n",
" self.value = value\n",
"\n",
"\n",
"class HashTable(object):\n",
"\n",
" def __init__(self, size):\n",
" self.size = size\n",
" self.table = [[] for _ in range(self.size)]\n",
"\n",
" def _hash_function(self, key):\n",
" return key % self.size\n",
"\n",
" def set(self, key, value):\n",
" hash_index = self._hash_function(key)\n",
" for item in self.table[hash_index]:\n",
" if item.key == key:\n",
" item.value = value\n",
" return\n",
" self.table[hash_index].append(Item(key, value))\n",
"\n",
" def get(self, key):\n",
" hash_index = self._hash_function(key)\n",
" for item in self.table[hash_index]:\n",
" if item.key == key:\n",
" return item.value\n",
" raise KeyError('Key not found')\n",
"\n",
" def remove(self, key):\n",
" hash_index = self._hash_function(key)\n",
" for index, item in enumerate(self.table[hash_index]):\n",
" if item.key == key:\n",
" del self.table[hash_index][index]\n",
" return\n",
" raise KeyError('Key not found')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_hash_map.py\n"
]
}
],
"source": [
"%%writefile test_hash_map.py\n",
"import unittest\n",
"\n",
"\n",
"class TestHashMap(unittest.TestCase):\n",
"\n",
" # TODO: It would be better if we had unit tests for each\n",
" # method in addition to the following end-to-end test\n",
" def test_end_to_end(self):\n",
" hash_table = HashTable(10)\n",
"\n",
" print(\"Test: get on an empty hash table index\")\n",
" self.assertRaises(KeyError, hash_table.get, 0)\n",
"\n",
" print(\"Test: set on an empty hash table index\")\n",
" hash_table.set(0, 'foo')\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" hash_table.set(1, 'bar')\n",
" self.assertEqual(hash_table.get(1), 'bar')\n",
"\n",
" print(\"Test: set on a non empty hash table index\")\n",
" hash_table.set(10, 'foo2')\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo2')\n",
"\n",
" print(\"Test: set on a key that already exists\")\n",
" hash_table.set(10, 'foo3')\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertEqual(hash_table.get(10), 'foo3')\n",
"\n",
" print(\"Test: remove on a key that already exists\")\n",
" hash_table.remove(10)\n",
" self.assertEqual(hash_table.get(0), 'foo')\n",
" self.assertRaises(KeyError, hash_table.get, 10)\n",
"\n",
" print(\"Test: remove on a key that doesn't exist\")\n",
" self.assertRaises(KeyError, hash_table.remove, -1)\n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestHashMap()\n",
" test.test_end_to_end()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Test: get on an empty hash table index\n",
"Test: set on an empty hash table index\n",
"Test: set on a non empty hash table index\n",
"Test: set on a key that already exists\n",
"Test: remove on a key that already exists\n",
"Test: remove on a key that doesn't exist\n",
"Success: test_end_to_end\n"
]
}
],
"source": [
"run -i test_hash_map.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/hash_map/test_hash_map.py
================================================
import unittest
class TestHashMap(unittest.TestCase):
# TODO: It would be better if we had unit tests for each
# method in addition to the following end-to-end test
def test_end_to_end(self):
hash_table = HashTable(10)
print("Test: get on an empty hash table index")
self.assertRaises(KeyError, hash_table.get, 0)
print("Test: set on an empty hash table index")
hash_table.set(0, 'foo')
self.assertEqual(hash_table.get(0), 'foo')
hash_table.set(1, 'bar')
self.assertEqual(hash_table.get(1), 'bar')
print("Test: set on a non empty hash table index")
hash_table.set(10, 'foo2')
self.assertEqual(hash_table.get(0), 'foo')
self.assertEqual(hash_table.get(10), 'foo2')
print("Test: set on a key that already exists")
hash_table.set(10, 'foo3')
self.assertEqual(hash_table.get(0), 'foo')
self.assertEqual(hash_table.get(10), 'foo3')
print("Test: remove on a key that already exists")
hash_table.remove(10)
self.assertEqual(hash_table.get(0), 'foo')
self.assertRaises(KeyError, hash_table.get, 10)
print("Test: remove on a key that doesn't exist")
self.assertRaises(KeyError, hash_table.remove, -1)
print('Success: test_end_to_end')
def main():
test = TestHashMap()
test.test_end_to_end()
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/permutation/__init__.py
================================================
================================================
FILE: arrays_strings/permutation/permutation_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Determine if a string is a permutation of another string.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is whitespace important?\n",
" * Yes\n",
"* Is this case sensitive? 'Nib', 'bin' is not a match?\n",
" * Yes\n",
"* Can we use additional data structures?\n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* One or more None inputs -> False\n",
"* One or more empty strings -> False\n",
"* 'Nib', 'bin' -> False\n",
"* 'act', 'cat' -> True\n",
"* 'a ct', 'ca t' -> True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/permutation/permutation_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Permutations(object):\n",
"\n",
" def is_permutation(self, str1, str2):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_permutation_solution.py\n",
"import unittest\n",
"\n",
"\n",
"class TestPermutation(unittest.TestCase):\n",
"\n",
" def test_permutation(self, func):\n",
" self.assertEqual(func(None, 'foo'), False)\n",
" self.assertEqual(func('', 'foo'), False)\n",
" self.assertEqual(func('Nib', 'bin'), False)\n",
" self.assertEqual(func('act', 'cat'), True)\n",
" self.assertEqual(func('a ct', 'ca t'), True)\n",
" self.assertEqual(func('dog', 'doggo'), False)\n",
" print('Success: test_permutation')\n",
"\n",
"\n",
"def main():\n",
" test = TestPermutation()\n",
" permutations = Permutations()\n",
" test.test_permutation(permutations.is_permutation)\n",
" try:\n",
" permutations_alt = PermutationsAlt()\n",
" test.test_permutation(permutations_alt.is_permutation)\n",
" except NameError:\n",
" # Alternate solutions are only defined\n",
" # in the solutions file\n",
" pass\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/permutation/permutation_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/permutation/permutation_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Determine if a string is a permutation of another string.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm: Compare Sorted Strings](#Algorithm:-Compare-Sorted-Strings)\n",
"* [Code: Compare Sorted Strings](#Code:-Compare-Sorted-Strings)\n",
"* [Algorithm: Hashmap Lookup](#Algorithm:-Hash-Map-Lookup)\n",
"* [Code: Hashmap Lookup](#Code:-Hash-Map-Lookup)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is whitespace important?\n",
" * Yes\n",
"* Is this case sensitive? 'Nib', 'bin' is not a match?\n",
" * Yes\n",
"* Can we use additional data structures?\n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* One or more None inputs -> False\n",
"* One or more empty strings -> False\n",
"* 'Nib', 'bin' -> False\n",
"* 'act', 'cat' -> True\n",
"* 'a ct', 'ca t' -> True\n",
"* 'dog', 'doggo' -> False"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm: Compare Sorted Strings\n",
"\n",
"Permutations contain the same strings but in different orders. This approach could be slow for large strings due to sorting.\n",
"\n",
"* Sort both strings\n",
"* If both sorted strings are equal\n",
" * return True\n",
"* Else\n",
" * return False\n",
"\n",
"Complexity:\n",
"* Time: O(n log n) from the sort, in general\n",
"* Space: O(n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code: Compare Sorted Strings"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"class Permutations(object):\n",
"\n",
" def is_permutation(self, str1, str2):\n",
" if str1 is None or str2 is None:\n",
" return False\n",
" return sorted(str1) == sorted(str2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm: Hash Map Lookup\n",
"\n",
"We'll keep a hash map (dict) to keep track of characters we encounter. \n",
"\n",
"Steps:\n",
"* Scan each character\n",
"* For each character in each string:\n",
" * If the character does not exist in a hash map, add the character to a hash map\n",
" * Else, increment the character's count\n",
"* If the hash maps for each string are equal\n",
" * Return True\n",
"* Else\n",
" * Return False\n",
"\n",
"Notes:\n",
"* Since the characters are in ASCII, we could potentially use an array of size 128 (or 256 for extended ASCII), where each array index is equivalent to an ASCII value\n",
"* Instead of using two hash maps, you could use one hash map and increment character values based on the first string and decrement based on the second string\n",
"* You can short circuit if the lengths of each string are not equal, although len() in Python is generally O(1) unlike other languages like C where getting the length of a string is O(n)\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code: Hash Map Lookup"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"\n",
"\n",
"class PermutationsAlt(object):\n",
"\n",
" def is_permutation(self, str1, str2):\n",
" if str1 is None or str2 is None:\n",
" return False\n",
" if len(str1) != len(str2):\n",
" return False\n",
" unique_counts1 = defaultdict(int)\n",
" unique_counts2 = defaultdict(int)\n",
" for char in str1:\n",
" unique_counts1[char] += 1\n",
" for char in str2:\n",
" unique_counts2[char] += 1\n",
" return unique_counts1 == unique_counts2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_permutation_solution.py\n"
]
}
],
"source": [
"%%writefile test_permutation_solution.py\n",
"import unittest\n",
"\n",
"\n",
"class TestPermutation(unittest.TestCase):\n",
"\n",
" def test_permutation(self, func):\n",
" self.assertEqual(func(None, 'foo'), False)\n",
" self.assertEqual(func('', 'foo'), False)\n",
" self.assertEqual(func('Nib', 'bin'), False)\n",
" self.assertEqual(func('act', 'cat'), True)\n",
" self.assertEqual(func('a ct', 'ca t'), True)\n",
" self.assertEqual(func('dog', 'doggo'), False)\n",
" print('Success: test_permutation')\n",
"\n",
"\n",
"def main():\n",
" test = TestPermutation()\n",
" permutations = Permutations()\n",
" test.test_permutation(permutations.is_permutation)\n",
" try:\n",
" permutations_alt = PermutationsAlt()\n",
" test.test_permutation(permutations_alt.is_permutation)\n",
" except NameError:\n",
" # Alternate solutions are only defined\n",
" # in the solutions file\n",
" pass\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_permutation\n",
"Success: test_permutation\n"
]
}
],
"source": [
"run -i test_permutation_solution.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/permutation/test_permutation_solution.py
================================================
import unittest
class TestPermutation(unittest.TestCase):
def test_permutation(self, func):
self.assertEqual(func(None, 'foo'), False)
self.assertEqual(func('', 'foo'), False)
self.assertEqual(func('Nib', 'bin'), False)
self.assertEqual(func('act', 'cat'), True)
self.assertEqual(func('a ct', 'ca t'), True)
self.assertEqual(func('dog', 'doggo'), False)
print('Success: test_permutation')
def main():
test = TestPermutation()
permutations = Permutations()
test.test_permutation(permutations.is_permutation)
try:
permutations_alt = PermutationsAlt()
test.test_permutation(permutations_alt.is_permutation)
except NameError:
# Alternate solutions are only defined
# in the solutions file
pass
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/priority_queue/__init__.py
================================================
================================================
FILE: arrays_strings/priority_queue/priority_queue.py
================================================
import sys
class PriorityQueueNode(object):
def __init__(self, obj, key):
self.obj = obj
self.key = key
def __repr__(self):
return str(self.obj) + ': ' + str(self.key)
class PriorityQueue(object):
def __init__(self):
self.array = []
def __len__(self):
return len(self.array)
def insert(self, node):
self.array.append(node)
return self.array[-1]
def extract_min(self):
if not self.array:
return None
minimum = sys.maxsize
for index, node in enumerate(self.array):
if node.key < minimum:
minimum = node.key
minimum_index = index
return self.array.pop(minimum_index)
def decrease_key(self, obj, new_key):
for node in self.array:
if node.obj is obj:
node.key = new_key
return node
return None
================================================
FILE: arrays_strings/priority_queue/priority_queue_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement a priority queue backed by an array.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Do we expect the methods to be insert, extract_min, and decrease_key?\n",
" * Yes\n",
"* Can we assume there aren't any duplicate keys?\n",
" * Yes\n",
"* Do we need to validate inputs?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"### insert\n",
"\n",
"* `insert` general case -> inserted node\n",
"\n",
"### extract_min\n",
"\n",
"* `extract_min` from an empty list -> None\n",
"* `extract_min` general case -> min node\n",
"\n",
"### decrease_key\n",
"\n",
"* `decrease_key` an invalid key -> None\n",
"* `decrease_key` general case -> updated node"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](priority_queue_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class PriorityQueueNode(object):\n",
"\n",
" def __init__(self, obj, key):\n",
" self.obj = obj\n",
" self.key = key\n",
"\n",
" def __repr__(self):\n",
" return str(self.obj) + ': ' + str(self.key)\n",
"\n",
"\n",
"class PriorityQueue(object):\n",
"\n",
" def __init__(self):\n",
" self.array = []\n",
"\n",
" def __len__(self):\n",
" return len(self.array)\n",
"\n",
" def insert(self, node):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def extract_min(self):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def decrease_key(self, obj, new_key):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_priority_queue.py\n",
"import unittest\n",
"\n",
"\n",
"class TestPriorityQueue(unittest.TestCase):\n",
"\n",
" def test_priority_queue(self):\n",
" priority_queue = PriorityQueue()\n",
" self.assertEqual(priority_queue.extract_min(), None)\n",
" priority_queue.insert(PriorityQueueNode('a', 20))\n",
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
" priority_queue.insert(PriorityQueueNode('d', 22))\n",
" priority_queue.insert(PriorityQueueNode('e', 40))\n",
" priority_queue.insert(PriorityQueueNode('f', 3))\n",
" priority_queue.decrease_key('f', 2)\n",
" priority_queue.decrease_key('a', 19)\n",
" mins = []\n",
" while priority_queue.array:\n",
" mins.append(priority_queue.extract_min().key)\n",
" self.assertEqual(mins, [2, 5, 15, 19, 22, 40])\n",
" print('Success: test_min_heap')\n",
"\n",
"\n",
"def main():\n",
" test = TestPriorityQueue()\n",
" test.test_priority_queue()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](priority_queue_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/priority_queue/priority_queue_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement a priority queue backed by an array.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Do we expect the methods to be insert, extract_min, and decrease_key?\n",
" * Yes\n",
"* Can we assume there aren't any duplicate keys?\n",
" * Yes\n",
"* Do we need to validate inputs?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"### insert\n",
"\n",
"* `insert` general case -> inserted node\n",
"\n",
"### extract_min\n",
"\n",
"* `extract_min` from an empty list -> None\n",
"* `extract_min` general case -> min node\n",
"\n",
"### decrease_key\n",
"\n",
"* `decrease_key` an invalid key -> None\n",
"* `decrease_key` general case -> updated node"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"### insert\n",
"\n",
"* Append to the internal array.\n",
"\n",
"Complexity:\n",
"* Time: O(1)\n",
"* Space: O(1)\n",
"\n",
"### extract_min\n",
"\n",
"* Loop through each item in the internal array\n",
" * Update the min value as needed\n",
"* Remove the min element from the array and return it\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(1)\n",
"\n",
"### decrease_key\n",
"\n",
"* Loop through each item in the internal array to find the matching input\n",
" * Update the matching element's key\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting priority_queue.py\n"
]
}
],
"source": [
"%%writefile priority_queue.py\n",
"import sys\n",
"\n",
"\n",
"class PriorityQueueNode(object):\n",
"\n",
" def __init__(self, obj, key):\n",
" self.obj = obj\n",
" self.key = key\n",
"\n",
" def __repr__(self):\n",
" return str(self.obj) + ': ' + str(self.key)\n",
"\n",
"\n",
"class PriorityQueue(object):\n",
"\n",
" def __init__(self):\n",
" self.array = []\n",
"\n",
" def __len__(self):\n",
" return len(self.array)\n",
"\n",
" def insert(self, node):\n",
" self.array.append(node)\n",
" return self.array[-1]\n",
"\n",
" def extract_min(self):\n",
" if not self.array:\n",
" return None\n",
" minimum = sys.maxsize\n",
" for index, node in enumerate(self.array):\n",
" if node.key < minimum:\n",
" minimum = node.key\n",
" minimum_index = index\n",
" return self.array.pop(minimum_index)\n",
"\n",
" def decrease_key(self, obj, new_key):\n",
" for node in self.array:\n",
" if node.obj is obj:\n",
" node.key = new_key\n",
" return node\n",
" return None"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%run priority_queue.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_priority_queue.py\n"
]
}
],
"source": [
"%%writefile test_priority_queue.py\n",
"import unittest\n",
"\n",
"\n",
"class TestPriorityQueue(unittest.TestCase):\n",
"\n",
" def test_priority_queue(self):\n",
" priority_queue = PriorityQueue()\n",
" self.assertEqual(priority_queue.extract_min(), None)\n",
" priority_queue.insert(PriorityQueueNode('a', 20))\n",
" priority_queue.insert(PriorityQueueNode('b', 5))\n",
" priority_queue.insert(PriorityQueueNode('c', 15))\n",
" priority_queue.insert(PriorityQueueNode('d', 22))\n",
" priority_queue.insert(PriorityQueueNode('e', 40))\n",
" priority_queue.insert(PriorityQueueNode('f', 3))\n",
" priority_queue.decrease_key('f', 2)\n",
" priority_queue.decrease_key('a', 19)\n",
" mins = []\n",
" while priority_queue.array:\n",
" mins.append(priority_queue.extract_min().key)\n",
" self.assertEqual(mins, [2, 5, 15, 19, 22, 40])\n",
" print('Success: test_min_heap')\n",
"\n",
"\n",
"def main():\n",
" test = TestPriorityQueue()\n",
" test.test_priority_queue()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_min_heap\n"
]
}
],
"source": [
"%run -i test_priority_queue.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/priority_queue/test_priority_queue.py
================================================
import unittest
class TestPriorityQueue(unittest.TestCase):
def test_priority_queue(self):
priority_queue = PriorityQueue()
self.assertEqual(priority_queue.extract_min(), None)
priority_queue.insert(PriorityQueueNode('a', 20))
priority_queue.insert(PriorityQueueNode('b', 5))
priority_queue.insert(PriorityQueueNode('c', 15))
priority_queue.insert(PriorityQueueNode('d', 22))
priority_queue.insert(PriorityQueueNode('e', 40))
priority_queue.insert(PriorityQueueNode('f', 3))
priority_queue.decrease_key('f', 2)
priority_queue.decrease_key('a', 19)
mins = []
while priority_queue.array:
mins.append(priority_queue.extract_min().key)
self.assertEqual(mins, [2, 5, 15, 19, 22, 40])
print('Success: test_min_heap')
def main():
test = TestPriorityQueue()
test.test_priority_queue()
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/reverse_string/__init__.py
================================================
================================================
FILE: arrays_strings/reverse_string/reverse_string.cpp
================================================
#include <stdio.h>
void Reverse(char* str) {
if (str) {
char* i = str; // first letter
char* j = str; // last letter
// find the end of the string
while (*j) {
j++;
}
// don't point to the null terminator
j--;
char tmp;
// swap chars to reverse the string
while (i < j) {
tmp = *i;
*i++ = *j;
*j-- = tmp;
}
}
}
int main() {
char test0[] = "";
char test1[] = "foo";
Reverse(NULL);
Reverse(test0);
Reverse(test1);
printf("%s \n", test0);
printf("%s \n", test1);
return 0;
}
================================================
FILE: arrays_strings/reverse_string/reverse_string_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement a function to reverse a string (a list of characters), in-place.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Since we need to do this in-place, it seems we cannot use the slice operator or the reversed function?\n",
" * Correct\n",
"* Since Python string are immutable, can we use a list of characters instead?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None -> None\n",
"* [''] -> ['']\n",
"* ['f', 'o', 'o', ' ', 'b', 'a', 'r'] -> ['r', 'a', 'b', ' ', 'o', 'o', 'f']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/reverse_string/reverse_string_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class ReverseString(object):\n",
"\n",
" def reverse(self, chars):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_reverse_string.py\n",
"import unittest\n",
"\n",
"\n",
"class TestReverse(unittest.TestCase):\n",
"\n",
" def test_reverse(self, func):\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(['']), [''])\n",
" self.assertEqual(func(\n",
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse')\n",
"\n",
" def test_reverse_inplace(self, func):\n",
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
" func(target_list)\n",
" self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse_inplace')\n",
"\n",
"\n",
"def main():\n",
" test = TestReverse()\n",
" reverse_string = ReverseString()\n",
" test.test_reverse(reverse_string.reverse)\n",
" test.test_reverse_inplace(reverse_string.reverse)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/reverse_string/reverse_string_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/reverse_string/reverse_string_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Implement a function to reverse a string (a list of characters), in-place.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Pythonic-Code](#Pythonic-Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Bonus C Algorithm](#Bonus-C-Algorithm)\n",
"* [Bonus C Code](#Bonus-C-Code)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Since we need to do this in-place, it seems we cannot use the slice operator or the reversed function?\n",
" * Correct\n",
"* Since Python string are immutable, can we use a list of characters instead?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None -> None\n",
"* [''] -> ['']\n",
"* ['f', 'o', 'o', ' ', 'b', 'a', 'r'] -> ['r', 'a', 'b', ' ', 'o', 'o', 'f']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Since Python strings are immutable, we'll use a list of chars instead to exercise in-place string manipulation as you would get with a C string.\n",
"\n",
"* Iterate len(string)/2 times, starting with i = 0:\n",
" * Swap char with index (i) and char with index (len(string) - 1 - i)\n",
" * Increment i\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(1)\n",
"\n",
"Note:\n",
"* You could use a byte array instead of a list to do in-place string operations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division\n",
"\n",
"\n",
"class ReverseString(object):\n",
"\n",
" def reverse(self, chars):\n",
" if chars:\n",
" size = len(chars)\n",
" for i in range(size // 2):\n",
" chars[i], chars[size - 1 - i] = \\\n",
" chars[size - 1 - i], chars[i]\n",
" return chars"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pythonic-Code\n",
"\n",
"This question has an artificial constraint that prevented the use of the slice operator and the reversed method. For completeness, the solutions for these are provided below. Note these solutions are not in-place."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"class ReverseStringAlt(object):\n",
"\n",
" def reverse_string_alt(string):\n",
" if string:\n",
" return string[::-1]\n",
" return string\n",
"\n",
" def reverse_string_alt2(string):\n",
" if string:\n",
" return ''.join(reversed(string))\n",
" return string"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_reverse_string.py\n"
]
}
],
"source": [
"%%writefile test_reverse_string.py\n",
"import unittest\n",
"\n",
"\n",
"class TestReverse(unittest.TestCase):\n",
"\n",
" def test_reverse(self, func):\n",
" self.assertEqual(func(None), None)\n",
" self.assertEqual(func(['']), [''])\n",
" self.assertEqual(func(\n",
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse')\n",
"\n",
" def test_reverse_inplace(self, func):\n",
" target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']\n",
" func(target_list)\n",
" self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse_inplace')\n",
"\n",
"\n",
"def main():\n",
" test = TestReverse()\n",
" reverse_string = ReverseString()\n",
" test.test_reverse(reverse_string.reverse)\n",
" test.test_reverse_inplace(reverse_string.reverse)\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_reverse\n",
"Success: test_reverse_inplace\n"
]
}
],
"source": [
"%run -i test_reverse_string.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## C Algorithm\n",
"\n",
"This is a classic problem in C/C++\n",
"\n",
"We'll want to keep two pointers:\n",
"* i is a pointer to the first char\n",
"* j is a pointer to the last char\n",
"\n",
"To get a pointer to the last char, we need to loop through all characters, take note of null terminator.\n",
"\n",
"* while i < j\n",
" * swap i and j\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: In-place\n",
"\n",
"Note:\n",
"* Instead of using i, you can use str instead, although this might not be as intuitive."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## C Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load reverse_string.cpp\n",
"#include <stdio.h>\n",
"\n",
"void Reverse(char* str) {\n",
" if (str) {\n",
" char* i = str;\t// first letter\n",
" char* j = str;\t// last letter\n",
" \n",
" // find the end of the string\n",
" while (*j) {\n",
" j++;\n",
" }\n",
" \n",
" // don't point to the null terminator\n",
" j--;\n",
" \n",
" char tmp;\n",
" \n",
" // swap chars to reverse the string\n",
" while (i < j) {\n",
" tmp = *i;\n",
" *i++ = *j;\n",
" *j-- = tmp;\n",
" }\n",
" }\n",
"}\n",
"\n",
"int main() {\n",
" char test0[] = \"\";\n",
" char test1[] = \"foo\";\n",
" Reverse(NULL);\n",
" Reverse(test0);\n",
" Reverse(test1);\n",
" printf(\"%s \\n\", test0);\n",
" printf(\"%s \\n\", test1);\n",
" return 0;\n",
"}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/reverse_string/test_reverse_string.py
================================================
import unittest
class TestReverse(unittest.TestCase):
def test_reverse(self, func):
self.assertEqual(func(None), None)
self.assertEqual(func(['']), [''])
self.assertEqual(func(
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
['r', 'a', 'b', ' ', 'o', 'o', 'f'])
print('Success: test_reverse')
def test_reverse_inplace(self, func):
target_list = ['f', 'o', 'o', ' ', 'b', 'a', 'r']
func(target_list)
self.assertEqual(target_list, ['r', 'a', 'b', ' ', 'o', 'o', 'f'])
print('Success: test_reverse_inplace')
def main():
test = TestReverse()
reverse_string = ReverseString()
test.test_reverse(reverse_string.reverse)
test.test_reverse_inplace(reverse_string.reverse)
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/rotation/__init__.py
================================================
================================================
FILE: arrays_strings/rotation/rotation_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Determine if a string s1 is a rotation of another string s2, by calling (only once) a function is_substring.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is this case sensitive?\n",
" * Yes\n",
"* Can we use additional data structures? \n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* Any strings that differ in size -> False\n",
"* None, 'foo' -> False (any None results in False)\n",
"* ' ', 'foo' -> False\n",
"* ' ', ' ' -> True\n",
"* 'foobarbaz', 'barbazfoo' -> True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/rotation/rotation_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Rotation(object):\n",
"\n",
" def is_substring(self, s1, s2):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def is_rotation(self, s1, s2):\n",
" # TODO: Implement me\n",
" # Call is_substring only once\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_rotation.py\n",
"import unittest\n",
"\n",
"\n",
"class TestRotation(unittest.TestCase):\n",
"\n",
" def test_rotation(self):\n",
" rotation = Rotation()\n",
" self.assertEqual(rotation.is_rotation('o', 'oo'), False)\n",
" self.assertEqual(rotation.is_rotation(None, 'foo'), False)\n",
" self.assertEqual(rotation.is_rotation('', 'foo'), False)\n",
" self.assertEqual(rotation.is_rotation('', ''), True)\n",
" self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
" print('Success: test_rotation')\n",
"\n",
"\n",
"def main():\n",
" test = TestRotation()\n",
" test.test_rotation()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/rotation/rotation_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/rotation/rotation_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](http://donnemartin.com). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Determine if a string s1 is a rotation of another string s2, by calling (only once) a function is_substring.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the string is ASCII?\n",
" * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n",
"* Is this case sensitive?\n",
" * Yes\n",
"* Can we use additional data structures? \n",
" * Yes\n",
"* Can we assume this fits in memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* Any strings that differ in size -> False\n",
"* None, 'foo' -> False (any None results in False)\n",
"* ' ', 'foo' -> False\n",
"* ' ', ' ' -> True\n",
"* 'foobarbaz', 'barbazfoo' -> True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Examine the following test case:\n",
"* s1 = 'barbazfoo'\n",
"* s2 = 'foobarbaz'\n",
"\n",
"We see that if we can use the given is_substring method if we take compare s2 with s1 + s1:\n",
"* s2 = 'foobarbaz'\n",
"* s3 = 'barbaz*foobarbaz*foo'\n",
"\n",
"Complexity:\n",
"* Time: O(n)\n",
"* Space: O(n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"class Rotation(object):\n",
"\n",
" def is_substring(self, s1, s2):\n",
" return s1 in s2\n",
"\n",
" def is_rotation(self, s1, s2):\n",
" if s1 is None or s2 is None:\n",
" return False\n",
" if len(s1) != len(s2):\n",
" return False\n",
" return self.is_substring(s1, s2 + s2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_rotation.py\n"
]
}
],
"source": [
"%%writefile test_rotation.py\n",
"import unittest\n",
"\n",
"\n",
"class TestRotation(unittest.TestCase):\n",
"\n",
" def test_rotation(self):\n",
" rotation = Rotation()\n",
" self.assertEqual(rotation.is_rotation('o', 'oo'), False)\n",
" self.assertEqual(rotation.is_rotation(None, 'foo'), False)\n",
" self.assertEqual(rotation.is_rotation('', 'foo'), False)\n",
" self.assertEqual(rotation.is_rotation('', ''), True)\n",
" self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)\n",
" print('Success: test_rotation')\n",
"\n",
"\n",
"def main():\n",
" test = TestRotation()\n",
" test.test_rotation()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_rotation\n"
]
}
],
"source": [
"%run -i test_rotation.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/rotation/test_rotation.py
================================================
import unittest
class TestRotation(unittest.TestCase):
def test_rotation(self):
rotation = Rotation()
self.assertEqual(rotation.is_rotation('o', 'oo'), False)
self.assertEqual(rotation.is_rotation(None, 'foo'), False)
self.assertEqual(rotation.is_rotation('', 'foo'), False)
self.assertEqual(rotation.is_rotation('', ''), True)
self.assertEqual(rotation.is_rotation('foobarbaz', 'barbazfoo'), True)
print('Success: test_rotation')
def main():
test = TestRotation()
test.test_rotation()
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/str_diff/__init__.py
================================================
================================================
FILE: arrays_strings/str_diff/str_diff_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Find the single different char between two strings.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the strings are ASCII?\n",
" * Yes\n",
"* Is case important?\n",
" * The strings are lower case\n",
"* Can we assume the inputs are valid?\n",
" * No, check for None\n",
" * Otherwise, assume there is only a single different char between the two strings\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None input -> TypeError\n",
"* 'ab', 'aab' -> 'a'\n",
"* 'aab', 'ab' -> 'a'\n",
"* 'abcd', 'abcde' -> 'e'\n",
"* 'aaabbcdd', 'abdbacade' -> 'e'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](str_diff_solution.ipynb). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
"\n",
" def find_diff(self, str1, str2):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_str_diff.py\n",
"import unittest\n",
"\n",
"\n",
"class TestFindDiff(unittest.TestCase):\n",
"\n",
" def test_find_diff(self):\n",
" solution = Solution()\n",
" self.assertRaises(TypeError, solution.find_diff, None)\n",
" self.assertEqual(solution.find_diff('ab', 'aab'), 'a')\n",
" self.assertEqual(solution.find_diff('aab', 'ab'), 'a')\n",
" self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')\n",
" self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
" self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')\n",
" self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')\n",
" self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
" self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
" print('Success: test_find_diff')\n",
"\n",
"\n",
"def main():\n",
" test = TestFindDiff()\n",
" test.test_find_diff()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook](http://nbviewer.jupyter.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/str_diff/str_diff_solution.ipynb) for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/str_diff/str_diff_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Find the single different char between two strings.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Can we assume the strings are ASCII?\n",
" * Yes\n",
"* Is case important?\n",
" * The strings are lower case\n",
"* Can we assume the inputs are valid?\n",
" * No, check for None\n",
" * Otherwise, assume there is only a single different char between the two strings\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None input -> TypeError\n",
"* 'ab', 'aab' -> 'a'\n",
"* 'aab', 'ab' -> 'a'\n",
"* 'abcd', 'abcde' -> 'e'\n",
"* 'aaabbcdd', 'abdbacade' -> 'e'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"### Dictionary\n",
"\n",
"* Keep a dictionary of seen values in s\n",
"* Loop through t, decrementing the seen values\n",
" * If the char is not there or if the decrement results in a negative value, return the char\n",
"* Return the differing char from the dictionary\n",
"\n",
"Complexity:\n",
"* Time: O(m+n), where m and n are the lengths of s, t\n",
"* Space: O(h), for the dict, where h is the unique chars in s\n",
"\n",
"### XOR\n",
"\n",
"* XOR the two strings, which will isolate the differing char\n",
"\n",
"Complexity:\n",
"* Time: O(m+n), where m and n are the lengths of s, t\n",
"* Space: O(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
"\n",
" def find_diff(self, str1, str2):\n",
" if str1 is None or str2 is None:\n",
" raise TypeError('str1 or str2 cannot be None')\n",
" seen = {}\n",
" for char in str1:\n",
" if char in seen:\n",
" seen[char] += 1\n",
" else:\n",
" seen[char] = 1\n",
" for char in str2:\n",
" try:\n",
" seen[char] -= 1\n",
" except KeyError:\n",
" return char\n",
" if seen[char] < 0:\n",
" return char\n",
" for char, count in seen.items():\n",
" return char\n",
"\n",
" def find_diff_xor(self, str1, str2):\n",
" if str1 is None or str2 is None:\n",
" raise TypeError('str1 or str2 cannot be None')\n",
" result = 0\n",
" for char in str1:\n",
" result ^= ord(char)\n",
" for char in str2:\n",
" result ^= ord(char)\n",
" return chr(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_str_diff.py\n"
]
}
],
"source": [
"%%writefile test_str_diff.py\n",
"import unittest\n",
"\n",
"\n",
"class TestFindDiff(unittest.TestCase):\n",
"\n",
" def test_find_diff(self):\n",
" solution = Solution()\n",
" self.assertRaises(TypeError, solution.find_diff, None)\n",
" self.assertEqual(solution.find_diff('ab', 'aab'), 'a')\n",
" self.assertEqual(solution.find_diff('aab', 'ab'), 'a')\n",
" self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')\n",
" self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')\n",
" self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')\n",
" self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')\n",
" self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')\n",
" self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')\n",
" print('Success: test_find_diff')\n",
"\n",
"\n",
"def main():\n",
" test = TestFindDiff()\n",
" test.test_find_diff()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_find_diff\n"
]
}
],
"source": [
"%run -i test_str_diff.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/str_diff/test_str_diff.py
================================================
import unittest
class TestFindDiff(unittest.TestCase):
def test_find_diff(self):
solution = Solution()
self.assertRaises(TypeError, solution.find_diff, None)
self.assertEqual(solution.find_diff('ab', 'aab'), 'a')
self.assertEqual(solution.find_diff('aab', 'ab'), 'a')
self.assertEqual(solution.find_diff('abcd', 'abcde'), 'e')
self.assertEqual(solution.find_diff('aaabbcdd', 'abdbacade'), 'e')
self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')
self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')
self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')
self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')
print('Success: test_find_diff')
def main():
test = TestFindDiff()
test.test_find_diff()
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/two_sum/__init__.py
================================================
================================================
FILE: arrays_strings/two_sum/test_two_sum.py
================================================
import unittest
class TestTwoSum(unittest.TestCase):
def test_two_sum(self):
solution = Solution()
self.assertRaises(TypeError, solution.two_sum, None, None)
self.assertRaises(ValueError, solution.two_sum, [], 0)
target = 7
nums = [1, 3, 2, -7, 5]
expected = [2, 4]
self.assertEqual(solution.two_sum(nums, target), expected)
print('Success: test_two_sum')
def main():
test = TestTwoSum()
test.test_two_sum()
if __name__ == '__main__':
main()
================================================
FILE: arrays_strings/two_sum/two_sum_challenge.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Given an array, find the two indices that sum to a specific value.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Is there exactly one solution?\n",
" * Yes\n",
"* Is there always a solution?\n",
" * Yes\n",
"* Is the array an array of ints?\n",
" * Yes\n",
"* Is the array sorted?\n",
" No\n",
"* Are negative values possible?\n",
" * Yes\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None input -> TypeError\n",
"* [] -> ValueError\n",
"* [1, 3, 2, -7, 5], 7 -> [2, 4]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
"\n",
" def two_sum(self, nums, val):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unit Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# %load test_two_sum.py\n",
"import unittest\n",
"\n",
"\n",
"class TestTwoSum(unittest.TestCase):\n",
"\n",
" def test_two_sum(self):\n",
" solution = Solution()\n",
" self.assertRaises(TypeError, solution.two_sum, None, None)\n",
" self.assertRaises(ValueError, solution.two_sum, [], 0)\n",
" target = 7\n",
" nums = [1, 3, 2, -7, 5]\n",
" expected = [2, 4]\n",
" self.assertEqual(solution.two_sum(nums, target), expected)\n",
" print('Success: test_two_sum')\n",
"\n",
"\n",
"def main():\n",
" test = TestTwoSum()\n",
" test.test_two_sum()\n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution Notebook\n",
"\n",
"Review the [Solution Notebook]() for a discussion on algorithms and code solutions."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
================================================
FILE: arrays_strings/two_sum/two_sum_solution.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solution Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem: Given an array, find the two indices that sum to a specific value.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints\n",
"\n",
"* Is there exactly one solution?\n",
" * Yes\n",
"* Is there always a solution?\n",
" * Yes\n",
"* Is the array an array of ints?\n",
" * Yes\n",
"* Is the array sorted?\n",
" No\n",
"* Are negative values possible?\n",
" * Yes\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test Cases\n",
"\n",
"* None input -> TypeError\n",
"* [] -> ValueError\n",
"* [1, 3, 2, -7, 5], 7 -> [2, 4]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Algorithm\n",
"\n",
"### Brute force\n",
"\n",
"* For i in range(len(input)):\n",
" * For j in range(i+1, len(input)):\n",
" * if i + j == target return True\n",
"* return False\n",
"\n",
"Complexity:\n",
"* Time: O(n^2)\n",
"* Space: O(1)\n",
"\n",
"### Optimized\n",
"\n",
"<pre>\n",
"* Loop through each num in nums\n",
" * Calculate the cache_target = target - num\n",
"\n",
"target = 7\n",
"index = 0 1 2 3 4\n",
"nums = [1, 3, 2, -7, 5]\n",
" ^\n",
"cache_target = 7 - 1 = 6\n",
"cache\n",
"6 -> 0\n",
"\n",
"1 not in cache\n",
"\n",
"index = 0 1 2 3 4\n",
"nums = [1, 3, 2, -7, 5]\n",
" ^\n",
"cache_target = 7 - 3 = 4\n",
"cache\n",
"6 -> 0\n",
"4 -> 1\n",
"\n",
"3 not in cache\n",
"\n",
"index = 0 1 2 3 4\n",
"nums = [1, 3, 2, -7, 5]\n",
" ^\n",
"cache_target = 7 - 2 = 5\n",
"cache\n",
"6 -> 0\n",
"4 -> 1\n",
"5 -> 2\n",
"\n",
"2 not in cache\n",
"\n",
"index = 0 1 2 3 4\n",
"nums = [1, 3, 2, -7, 5]\n",
" ^\n",
"cache_target = 7 + 7 = 14\n",
"cache\n",
"6 -> 0\n",
"4 -> 1\n",
"5 -> 2\n",
"14 -> 3\n",
"\n",
"-7 not in cache\n",
"\n",
"index = 0 1 2 3 4\n",
"nums = [1, 3, 2, -7, 5]\n",
"
gitextract_0a45doj9/
├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── __init__.py
├── anki_cards/
│ └── Coding.apkg
├── arrays_strings/
│ ├── __init__.py
│ ├── compress/
│ │ ├── __init__.py
│ │ ├── compress_challenge.ipynb
│ │ ├── compress_solution.ipynb
│ │ └── test_compress.py
│ ├── compress_alt/
│ │ ├── __init__.py
│ │ ├── better_compress_challenge.ipynb
│ │ ├── better_compress_solution.ipynb
│ │ └── test_compress.py
│ ├── fizz_buzz/
│ │ ├── __init__.py
│ │ ├── fizz_buzz_challenge.ipynb
│ │ ├── fizz_buzz_solution.ipynb
│ │ └── test_fizz_buzz.py
│ ├── hash_map/
│ │ ├── __init__.py
│ │ ├── hash_map_challenge.ipynb
│ │ ├── hash_map_solution.ipynb
│ │ └── test_hash_map.py
│ ├── permutation/
│ │ ├── __init__.py
│ │ ├── permutation_challenge.ipynb
│ │ ├── permutation_solution.ipynb
│ │ └── test_permutation_solution.py
│ ├── priority_queue/
│ │ ├── __init__.py
│ │ ├── priority_queue.py
│ │ ├── priority_queue_challenge.ipynb
│ │ ├── priority_queue_solution.ipynb
│ │ └── test_priority_queue.py
│ ├── reverse_string/
│ │ ├── __init__.py
│ │ ├── reverse_string.cpp
│ │ ├── reverse_string_challenge.ipynb
│ │ ├── reverse_string_solution.ipynb
│ │ └── test_reverse_string.py
│ ├── rotation/
│ │ ├── __init__.py
│ │ ├── rotation_challenge.ipynb
│ │ ├── rotation_solution.ipynb
│ │ └── test_rotation.py
│ ├── str_diff/
│ │ ├── __init__.py
│ │ ├── str_diff_challenge.ipynb
│ │ ├── str_diff_solution.ipynb
│ │ └── test_str_diff.py
│ ├── two_sum/
│ │ ├── __init__.py
│ │ ├── test_two_sum.py
│ │ ├── two_sum_challenge.ipynb
│ │ └── two_sum_solution.ipynb
│ └── unique_chars/
│ ├── __init__.py
│ ├── test_unique_chars.py
│ ├── unique_chars_challenge.ipynb
│ └── unique_chars_solution.ipynb
├── bit_manipulation/
│ ├── __init__.py
│ ├── bit/
│ │ ├── __init__.py
│ │ ├── bit_challenge.ipynb
│ │ ├── bit_solution.ipynb
│ │ └── test_bit.py
│ ├── bits_to_flip/
│ │ ├── __init__.py
│ │ ├── bits_to_flip_challenge.ipynb
│ │ ├── bits_to_flip_solution.ipynb
│ │ └── test_bits_to_flip.py
│ ├── draw_line/
│ │ ├── __init__.py
│ │ ├── draw_line_challenge.ipynb
│ │ ├── draw_line_solution.ipynb
│ │ └── test_draw_line.py
│ ├── flip_bit/
│ │ ├── __init__.py
│ │ ├── flip_bit_challenge.ipynb
│ │ ├── flip_bit_solution.ipynb
│ │ └── test_flip_bit.py
│ ├── get_next/
│ │ ├── __init__.py
│ │ ├── get_next_challenge.ipynb
│ │ ├── get_next_solution.ipynb
│ │ └── test_get_next_largest.py
│ ├── insert_m_into_n/
│ │ ├── __init__.py
│ │ ├── insert_m_into_n_challenge.ipynb
│ │ ├── insert_m_into_n_solution.ipynb
│ │ └── test_insert_m_into_n.py
│ ├── pairwise_swap/
│ │ ├── __init__.py
│ │ ├── pairwise_swap_challenge.ipynb
│ │ ├── pairwise_swap_solution.ipynb
│ │ └── test_pairwise_swap.py
│ └── print_binary/
│ ├── __init__.py
│ ├── print_binary_challenge.ipynb
│ ├── print_binary_solution.ipynb
│ └── test_print_binary.py
├── graphs_trees/
│ ├── __init__.py
│ ├── bst/
│ │ ├── __init__.py
│ │ ├── bst.py
│ │ ├── bst_challenge.ipynb
│ │ ├── bst_solution.ipynb
│ │ ├── dfs.py
│ │ └── test_bst.py
│ ├── bst_min/
│ │ ├── __init__.py
│ │ ├── bst_min_challenge.ipynb
│ │ ├── bst_min_solution.ipynb
│ │ └── test_bst_min.py
│ ├── bst_second_largest/
│ │ ├── __init__.py
│ │ ├── bst_second_largest_challenge.ipynb
│ │ ├── bst_second_largest_solution.ipynb
│ │ └── test_bst_second_largest.py
│ ├── bst_successor/
│ │ ├── __init__.py
│ │ ├── bst_successor_challenge.ipynb
│ │ ├── bst_successor_solution.ipynb
│ │ └── test_bst_successor.py
│ ├── bst_validate/
│ │ ├── __init__.py
│ │ ├── bst_validate_challenge.ipynb
│ │ ├── bst_validate_solution.ipynb
│ │ └── test_bst_validate.py
│ ├── check_balance/
│ │ ├── __init__.py
│ │ ├── check_balance_challenge.ipynb
│ │ ├── check_balance_solution.ipynb
│ │ └── test_check_balance.py
│ ├── graph/
│ │ ├── __init__.py
│ │ ├── graph.py
│ │ ├── graph_challenge.ipynb
│ │ ├── graph_solution.ipynb
│ │ └── test_graph.py
│ ├── graph_bfs/
│ │ ├── __init__.py
│ │ ├── bfs_challenge.ipynb
│ │ ├── bfs_solution.ipynb
│ │ └── test_bfs.py
│ ├── graph_build_order/
│ │ ├── __init__.py
│ │ ├── build_order_challenge.ipynb
│ │ ├── build_order_solution.ipynb
│ │ └── test_build_order.py
│ ├── graph_dfs/
│ │ ├── __init__.py
│ │ ├── dfs_challenge.ipynb
│ │ ├── dfs_solution.ipynb
│ │ └── test_dfs.py
│ ├── graph_path_exists/
│ │ ├── __init__.py
│ │ ├── path_exists_challenge.ipynb
│ │ ├── path_exists_solution.ipynb
│ │ └── test_path_exists.py
│ ├── graph_shortest_path/
│ │ ├── __init__.py
│ │ ├── graph_shortest_path_challenge.ipynb
│ │ ├── graph_shortest_path_solution.ipynb
│ │ ├── priority_queue.py
│ │ └── test_shortest_path.py
│ ├── graph_shortest_path_unweighted/
│ │ ├── __init__.py
│ │ ├── shortest_path_challenge.ipynb
│ │ ├── shortest_path_solution.ipynb
│ │ └── test_shortest_path.py
│ ├── invert_tree/
│ │ ├── __init__.py
│ │ ├── invert_tree_challenge.ipynb
│ │ ├── invert_tree_solution.ipynb
│ │ └── test_invert_tree.py
│ ├── min_heap/
│ │ ├── __init__.py
│ │ ├── min_heap.py
│ │ ├── min_heap_challenge.ipynb
│ │ ├── min_heap_solution.ipynb
│ │ └── test_min_heap.py
│ ├── tree_bfs/
│ │ ├── __init__.py
│ │ ├── bfs_challenge.ipynb
│ │ ├── bfs_solution.ipynb
│ │ └── test_bfs.py
│ ├── tree_dfs/
│ │ ├── __init__.py
│ │ ├── dfs_challenge.ipynb
│ │ ├── dfs_solution.ipynb
│ │ └── test_dfs.py
│ ├── tree_height/
│ │ ├── __init__.py
│ │ ├── height.py
│ │ ├── height_challenge.ipynb
│ │ ├── height_solution.ipynb
│ │ └── test_height.py
│ ├── tree_lca/
│ │ ├── __init__.py
│ │ ├── test_lca.py
│ │ ├── tree_lca_challenge.ipynb
│ │ └── tree_lca_solution.ipynb
│ ├── tree_level_lists/
│ │ ├── __init__.py
│ │ ├── test_tree_level_lists.py
│ │ ├── tree_level_lists_challenge.ipynb
│ │ └── tree_level_lists_solution.ipynb
│ ├── trie/
│ │ ├── __init__.py
│ │ ├── test_trie.py
│ │ ├── trie.py
│ │ ├── trie_challenge.ipynb
│ │ └── trie_solution.ipynb
│ └── utils/
│ ├── __init__.py
│ ├── captured_output.py
│ └── results.py
├── linked_lists/
│ ├── __init__.py
│ ├── add_reverse/
│ │ ├── __init__.py
│ │ ├── add_reverse_challenge.ipynb
│ │ ├── add_reverse_solution.ipynb
│ │ └── test_add_reverse.py
│ ├── delete_mid/
│ │ ├── __init__.py
│ │ ├── delete_mid_challenge.ipynb
│ │ ├── delete_mid_solution.ipynb
│ │ └── test_delete_mid.py
│ ├── find_loop_start/
│ │ ├── __init__.py
│ │ ├── find_loop_start_challenge.ipynb
│ │ ├── find_loop_start_solution.ipynb
│ │ └── test_find_loop_start.py
│ ├── kth_to_last_elem/
│ │ ├── __init__.py
│ │ ├── kth_to_last_elem_challenge.ipynb
│ │ ├── kth_to_last_elem_solution.ipynb
│ │ └── test_kth_to_last_elem.py
│ ├── linked_list/
│ │ ├── __init__.py
│ │ ├── linked_list.py
│ │ ├── linked_list_challenge.ipynb
│ │ ├── linked_list_solution.ipynb
│ │ └── test_linked_list.py
│ ├── palindrome/
│ │ ├── __init__.py
│ │ ├── palindrome_challenge.ipynb
│ │ ├── palindrome_solution.ipynb
│ │ └── test_palindrome.py
│ ├── partition/
│ │ ├── __init__.py
│ │ ├── partition_challenge.ipynb
│ │ ├── partition_solution.ipynb
│ │ └── test_partition.py
│ └── remove_duplicates/
│ ├── __init__.py
│ ├── remove_duplicates_challenge.ipynb
│ ├── remove_duplicates_solution.ipynb
│ └── test_remove_duplicates.py
├── math_probability/
│ ├── add_digits/
│ │ ├── __init__.py
│ │ ├── add_digits_challenge.ipynb
│ │ ├── add_digits_solution.ipynb
│ │ └── test_add_digits.py
│ ├── check_prime/
│ │ ├── __init__.py
│ │ ├── check_prime_challenge.ipynb
│ │ ├── check_prime_solution.ipynb
│ │ └── test_check_prime.py
│ ├── generate_primes/
│ │ ├── __init__.py
│ │ ├── check_prime_challenge.ipynb
│ │ ├── check_prime_solution.ipynb
│ │ └── test_generate_primes.py
│ ├── math_ops/
│ │ ├── __init__.py
│ │ ├── math_ops_challenge.ipynb
│ │ ├── math_ops_solution.ipynb
│ │ └── test_math_ops.py
│ ├── power_two/
│ │ ├── __init__.py
│ │ ├── power_two_challenge.ipynb
│ │ ├── power_two_solution.ipynb
│ │ └── test_is_power_of_two.py
│ ├── sub_two/
│ │ ├── __init__.py
│ │ ├── sub_two_challenge.ipynb
│ │ ├── sub_two_solution.ipynb
│ │ └── test_sub_two.py
│ └── sum_two/
│ ├── __init__.py
│ ├── sum_two_challenge.ipynb
│ ├── sum_two_solution.ipynb
│ └── test_sum_two.py
├── online_judges/
│ ├── __init__.py
│ ├── assign_cookies/
│ │ ├── __init__.py
│ │ ├── assign_cookies_challenge.ipynb
│ │ ├── assign_cookies_solution.ipynb
│ │ └── test_assign_cookie.py
│ ├── busiest_period/
│ │ ├── __init__.py
│ │ ├── busiest_period_challenge.ipynb
│ │ ├── busiest_period_solution.ipynb
│ │ └── test_find_busiest_period.py
│ ├── island_perimeter/
│ │ ├── __init__.py
│ │ ├── island_perimeter_challenge.ipynb
│ │ ├── island_perimeter_solution.ipynb
│ │ └── test_island_perimeter.py
│ ├── license_key/
│ │ ├── __init__.py
│ │ ├── format_license_key_challenge.ipynb
│ │ ├── format_license_key_solution.ipynb
│ │ └── test_format_license_key.py
│ ├── longest_abs_file_path/
│ │ ├── __init__.py
│ │ ├── longest_path_challenge.ipynb
│ │ ├── longest_path_solution.ipynb
│ │ └── test_length_longest_path.py
│ ├── longest_substr_k_distinct/
│ │ ├── __init__.py
│ │ ├── longest_substr_challenge.ipynb
│ │ ├── longest_substr_solution.ipynb
│ │ └── test_longest_substr.py
│ ├── math_ops/
│ │ ├── __init__.py
│ │ ├── math_ops_challenge.ipynb
│ │ ├── math_ops_solution.ipynb
│ │ └── test_math_ops.py
│ ├── max_profit/
│ │ ├── __init__.py
│ │ ├── max_profit_challenge.ipynb
│ │ ├── max_profit_solution.ipynb
│ │ └── test_max_profit.py
│ ├── maximizing_xor/
│ │ ├── __init__.py
│ │ ├── maximizing_xor_challenge.ipynb
│ │ ├── maximizing_xor_solution.ipynb
│ │ └── test_maximizing_xor.py
│ ├── merge_ranges/
│ │ ├── __init__.py
│ │ ├── merge_ranges_challenge.ipynb
│ │ ├── merge_ranges_solution.ipynb
│ │ └── test_merge_ranges.py
│ ├── move_zeroes/
│ │ ├── __init__.py
│ │ ├── move_zeroes_challenge.ipynb
│ │ ├── move_zeroes_solution.ipynb
│ │ └── test_move_zeroes.py
│ ├── mult_other_numbers/
│ │ ├── __init__.py
│ │ ├── mult_other_numbers_challenge.ipynb
│ │ ├── mult_other_numbers_solution.ipynb
│ │ └── test_mult_other_numbers.py
│ ├── nim/
│ │ ├── __init__.py
│ │ ├── nim_challenge.ipynb
│ │ ├── nim_solution.ipynb
│ │ └── test_can_win_nim.py
│ ├── prod_three/
│ │ ├── __init__.py
│ │ ├── prod_three_challenge.ipynb
│ │ ├── prod_three_solution.ipynb
│ │ └── test_prod_three.py
│ ├── ransom_note/
│ │ ├── __init__.py
│ │ ├── ransom_note_challenge.ipynb
│ │ ├── ransom_note_solution.ipynb
│ │ └── test_ransom_note.py
│ ├── sentence_screen_fit/
│ │ ├── __init__.py
│ │ ├── sentence_screen_fit_challenge.ipynb
│ │ ├── sentence_screen_fit_solution.ipynb
│ │ └── test_count_sentence_fit.py
│ ├── str_diff/
│ │ ├── __init__.py
│ │ ├── str_diff_challenge.ipynb
│ │ ├── str_diff_solution.ipynb
│ │ └── test_str_diff.py
│ ├── sub_two/
│ │ ├── sub_two_challenge.ipynb
│ │ ├── sub_two_solution.ipynb
│ │ └── test_sub_two.py
│ ├── sum_two/
│ │ ├── sum_two_challenge.ipynb
│ │ ├── sum_two_solution.ipynb
│ │ └── test_sum_two.py
│ └── utopian_tree/
│ ├── __init__.py
│ ├── test_utopian_tree.py
│ ├── utopian_tree_challenge.ipynb
│ └── utopian_tree_solution.ipynb
├── recursion_dynamic/
│ ├── __init__.py
│ ├── coin_change/
│ │ ├── __init__.py
│ │ ├── coin_change_challenge.ipynb
│ │ ├── coin_change_solution.ipynb
│ │ └── test_coin_change.py
│ ├── coin_change_min/
│ │ ├── __init__.py
│ │ ├── coin_change_min_challenge.ipynb
│ │ ├── coin_change_min_solution.ipynb
│ │ └── test_coin_change_min.py
│ ├── coin_change_ways/
│ │ ├── __init__.py
│ │ ├── coin_change_ways_challenge.ipynb
│ │ ├── coin_change_ways_solution.ipynb
│ │ └── test_coin_change_ways.py
│ ├── fibonacci/
│ │ ├── __init__.py
│ │ ├── fibonacci_challenge.ipynb
│ │ ├── fibonacci_solution.ipynb
│ │ └── test_fibonacci.py
│ ├── grid_path/
│ │ ├── __init__.py
│ │ ├── grid_path_challenge.ipynb
│ │ ├── grid_path_solution.ipynb
│ │ └── test_grid_path.py
│ ├── hanoi/
│ │ ├── __init__.py
│ │ ├── hanoi_challenge.ipynb
│ │ ├── hanoi_solution.ipynb
│ │ └── test_hanoi.py
│ ├── knapsack_01/
│ │ ├── __init__.py
│ │ ├── knapsack_challenge.ipynb
│ │ ├── knapsack_solution.ipynb
│ │ └── test_knapsack.py
│ ├── knapsack_unbounded/
│ │ ├── __init__.py
│ │ ├── knapsack_unbounded_challenge.ipynb
│ │ ├── knapsack_unbounded_solution.ipynb
│ │ └── test_knapsack_unbounded.py
│ ├── longest_common_subsequence/
│ │ ├── __init__.py
│ │ ├── longest_common_subseq_challenge.ipynb
│ │ ├── longest_common_subseq_solution.ipynb
│ │ └── test_longest_common_subseq.py
│ ├── longest_inc_subseq/
│ │ ├── __init__.py
│ │ ├── longest_inc_subseq_challenge.ipynb
│ │ ├── longest_inc_subseq_solution.ipynb
│ │ └── test_longest_increasing_subseq.py
│ ├── longest_substr_k_distinct/
│ │ ├── __init__.py
│ │ ├── longest_substr_challenge.ipynb
│ │ ├── longest_substr_solution.ipynb
│ │ └── test_longest_substr.py
│ ├── longest_substring/
│ │ ├── __init__.py
│ │ ├── longest_common_substr_challenge.ipynb
│ │ ├── longest_common_substr_solution.ipynb
│ │ └── test_longest_common_substr.py
│ ├── magic_index/
│ │ ├── __init__.py
│ │ ├── magic_index_challenge.ipynb
│ │ ├── magic_index_solution.ipynb
│ │ └── test_find_magic_index.py
│ ├── matrix_mult/
│ │ ├── __init__.py
│ │ ├── find_min_cost_challenge.ipynb
│ │ ├── find_min_cost_solution.ipynb
│ │ └── test_find_min_cost.py
│ ├── max_profit_k/
│ │ ├── __init__.py
│ │ ├── max_profit_challenge.ipynb
│ │ ├── max_profit_solution.ipynb
│ │ └── test_max_profit.py
│ ├── n_pairs_parentheses/
│ │ ├── __init__.py
│ │ ├── n_pairs_parentheses_challenge.ipynb
│ │ ├── n_pairs_parentheses_solution.ipynb
│ │ └── test_n_pairs_parentheses.py
│ ├── permutations/
│ │ ├── __init__.py
│ │ ├── permutations_challenge.ipynb
│ │ ├── permutations_solution.ipynb
│ │ └── test_permutations.py
│ ├── power_set/
│ │ ├── __init__.py
│ │ ├── power_set_challenge.ipynb
│ │ ├── power_set_solution.ipynb
│ │ └── test_power_set.py
│ └── steps/
│ ├── __init__.py
│ ├── steps_challenge.ipynb
│ ├── steps_solution.ipynb
│ └── test_steps.py
├── requirements.txt
├── sorting_searching/
│ ├── __init__.py
│ ├── anagrams/
│ │ ├── __init__.py
│ │ ├── anagrams_challenge.ipynb
│ │ ├── anagrams_solution.ipynb
│ │ └── test_anagrams.py
│ ├── insertion_sort/
│ │ ├── __init__.py
│ │ ├── insertion_sort_challenge.ipynb
│ │ ├── insertion_sort_solution.ipynb
│ │ └── test_insertion_sort.py
│ ├── merge_into/
│ │ ├── __init__.py
│ │ ├── merge_into_challenge.ipynb
│ │ ├── merge_into_solution.ipynb
│ │ └── test_merge_into.py
│ ├── merge_sort/
│ │ ├── __init__.py
│ │ ├── merge_sort_challenge.ipynb
│ │ ├── merge_sort_solution.ipynb
│ │ └── test_merge_sort.py
│ ├── new_int/
│ │ ├── __init__.py
│ │ ├── new_int_challenge.ipynb
│ │ ├── new_int_solution.ipynb
│ │ └── test_new_int.py
│ ├── quick_sort/
│ │ ├── __init__.py
│ │ ├── quick_sort_challenge.ipynb
│ │ ├── quick_sort_solution.ipynb
│ │ └── test_quick_sort.py
│ ├── radix_sort/
│ │ ├── __init__.py
│ │ ├── radix_sort_challenge.ipynb
│ │ ├── radix_sort_solution.ipynb
│ │ └── test_radix_sort.py
│ ├── rotated_array_search/
│ │ ├── __init__.py
│ │ ├── rotated_array_search_challenge.ipynb
│ │ ├── rotated_array_search_solution.ipynb
│ │ └── test_search_sorted_array.py
│ ├── search_sorted_matrix/
│ │ ├── __init__.py
│ │ ├── search_sorted_matrix_challenge.ipynb
│ │ ├── search_sorted_matrix_solution.ipynb
│ │ └── test_search_sorted_matrix.py
│ └── selection_sort/
│ ├── __init__.py
│ ├── selection_sort_challenge.ipynb
│ ├── selection_sort_solution.ipynb
│ └── test_selection_sort.py
├── stacks_queues/
│ ├── __init__.py
│ ├── n_stacks/
│ │ ├── __init__.py
│ │ ├── n_stacks_challenge.ipynb
│ │ ├── n_stacks_solution.ipynb
│ │ └── test_n_stacks.py
│ ├── queue_from_stacks/
│ │ ├── __init__.py
│ │ ├── queue_from_stacks_challenge.ipynb
│ │ ├── queue_from_stacks_solution.ipynb
│ │ └── test_queue_from_stacks.py
│ ├── queue_list/
│ │ ├── __init__.py
│ │ ├── queue_list.py
│ │ ├── queue_list_challenge.ipynb
│ │ ├── queue_list_solution.ipynb
│ │ └── test_queue_list.py
│ ├── set_of_stacks/
│ │ ├── __init__.py
│ │ ├── set_of_stacks_challenge.ipynb
│ │ ├── set_of_stacks_solution.ipynb
│ │ └── test_set_of_stacks.py
│ ├── sort_stack/
│ │ ├── __init__.py
│ │ ├── sort_stack_challenge.ipynb
│ │ ├── sort_stack_solution.ipynb
│ │ └── test_sort_stack.py
│ ├── stack/
│ │ ├── __init__.py
│ │ ├── stack.py
│ │ ├── stack_challenge.ipynb
│ │ ├── stack_solution.ipynb
│ │ └── test_stack.py
│ └── stack_min/
│ ├── __init__.py
│ ├── stack_min_challenge.ipynb
│ ├── stack_min_solution.ipynb
│ └── test_stack_min.py
├── staging/
│ ├── README.md
│ ├── __init__.py
│ ├── arrays_strings/
│ │ ├── __init__.py
│ │ └── reverse_words/
│ │ ├── __init__.py
│ │ ├── reverse_words_challenge.ipynb
│ │ ├── reverse_words_solution.ipynb
│ │ └── reverse_words_solution.py
│ ├── graphs_trees/
│ │ ├── __init__.py
│ │ └── binary_tree/
│ │ ├── __init__.py
│ │ ├── binary_search_tree.py
│ │ ├── binary_tree_challenge.ipynb
│ │ ├── binary_tree_solution.ipynb
│ │ └── test_binary_search_tree.py
│ ├── linked_lists/
│ │ └── __init__.py
│ ├── online_judges/
│ │ └── __init__.py
│ ├── recursion_dynamic/
│ │ └── __init__.py
│ ├── sorting_searching/
│ │ ├── __init__.py
│ │ └── group_ordered/
│ │ ├── __init__.py
│ │ ├── group_ordered_challenge.ipynb
│ │ ├── group_ordered_solution.ipynb
│ │ └── test_group_ordered.py
│ └── stacks_queues/
│ └── __init__.py
└── templates/
├── __init__.py
├── foo_challenge.ipynb
├── foo_solution.ipynb
└── test_foo.py
SYMBOL INDEX (479 symbols across 130 files)
FILE: arrays_strings/compress/test_compress.py
class TestCompress (line 4) | class TestCompress(unittest.TestCase):
method test_compress (line 6) | def test_compress(self, func):
function main (line 16) | def main():
FILE: arrays_strings/compress_alt/test_compress.py
class TestCompress (line 4) | class TestCompress(unittest.TestCase):
method test_compress (line 6) | def test_compress(self, func):
function main (line 18) | def main():
FILE: arrays_strings/fizz_buzz/test_fizz_buzz.py
class TestFizzBuzz (line 4) | class TestFizzBuzz(unittest.TestCase):
method test_fizz_buzz (line 6) | def test_fizz_buzz(self):
function main (line 31) | def main():
FILE: arrays_strings/hash_map/test_hash_map.py
class TestHashMap (line 4) | class TestHashMap(unittest.TestCase):
method test_end_to_end (line 8) | def test_end_to_end(self):
function main (line 41) | def main():
FILE: arrays_strings/permutation/test_permutation_solution.py
class TestPermutation (line 4) | class TestPermutation(unittest.TestCase):
method test_permutation (line 6) | def test_permutation(self, func):
function main (line 16) | def main():
FILE: arrays_strings/priority_queue/priority_queue.py
class PriorityQueueNode (line 4) | class PriorityQueueNode(object):
method __init__ (line 6) | def __init__(self, obj, key):
method __repr__ (line 10) | def __repr__(self):
class PriorityQueue (line 14) | class PriorityQueue(object):
method __init__ (line 16) | def __init__(self):
method __len__ (line 19) | def __len__(self):
method insert (line 22) | def insert(self, node):
method extract_min (line 26) | def extract_min(self):
method decrease_key (line 36) | def decrease_key(self, obj, new_key):
FILE: arrays_strings/priority_queue/test_priority_queue.py
class TestPriorityQueue (line 4) | class TestPriorityQueue(unittest.TestCase):
method test_priority_queue (line 6) | def test_priority_queue(self):
function main (line 24) | def main():
FILE: arrays_strings/reverse_string/reverse_string.cpp
function Reverse (line 3) | void Reverse(char* str) {
function main (line 27) | int main() {
FILE: arrays_strings/reverse_string/test_reverse_string.py
class TestReverse (line 4) | class TestReverse(unittest.TestCase):
method test_reverse (line 6) | def test_reverse(self, func):
method test_reverse_inplace (line 14) | def test_reverse_inplace(self, func):
function main (line 21) | def main():
FILE: arrays_strings/rotation/test_rotation.py
class TestRotation (line 4) | class TestRotation(unittest.TestCase):
method test_rotation (line 6) | def test_rotation(self):
function main (line 16) | def main():
FILE: arrays_strings/str_diff/test_str_diff.py
class TestFindDiff (line 4) | class TestFindDiff(unittest.TestCase):
method test_find_diff (line 6) | def test_find_diff(self):
function main (line 20) | def main():
FILE: arrays_strings/two_sum/test_two_sum.py
class TestTwoSum (line 4) | class TestTwoSum(unittest.TestCase):
method test_two_sum (line 6) | def test_two_sum(self):
function main (line 17) | def main():
FILE: arrays_strings/unique_chars/test_unique_chars.py
class TestUniqueChars (line 4) | class TestUniqueChars(unittest.TestCase):
method test_unique_chars (line 6) | def test_unique_chars(self, func):
function main (line 14) | def main():
FILE: bit_manipulation/bit/test_bit.py
class TestBit (line 4) | class TestBit(unittest.TestCase):
method test_bit (line 6) | def test_bit(self):
function main (line 32) | def main():
FILE: bit_manipulation/bits_to_flip/test_bits_to_flip.py
class TestBits (line 4) | class TestBits(unittest.TestCase):
method test_bits_to_flip (line 6) | def test_bits_to_flip(self):
function main (line 15) | def main():
FILE: bit_manipulation/draw_line/test_draw_line.py
class TestBitsScreen (line 4) | class TestBitsScreen(unittest.TestCase):
method test_draw_line (line 6) | def test_draw_line(self):
function main (line 22) | def main():
FILE: bit_manipulation/flip_bit/test_flip_bit.py
class TestBits (line 4) | class TestBits(unittest.TestCase):
method test_flip_bit (line 6) | def test_flip_bit(self):
function main (line 23) | def main():
FILE: bit_manipulation/get_next/test_get_next_largest.py
class TestBits (line 4) | class TestBits(unittest.TestCase):
method test_get_next_largest (line 6) | def test_get_next_largest(self):
method test_get_next_smallest (line 16) | def test_get_next_smallest(self):
function main (line 26) | def main():
FILE: bit_manipulation/insert_m_into_n/test_insert_m_into_n.py
class TestBit (line 4) | class TestBit(unittest.TestCase):
method test_insert_m_into_n (line 6) | def test_insert_m_into_n(self):
function main (line 15) | def main():
FILE: bit_manipulation/pairwise_swap/test_pairwise_swap.py
class TestBits (line 4) | class TestBits(unittest.TestCase):
method test_pairwise_swap (line 6) | def test_pairwise_swap(self):
function main (line 18) | def main():
FILE: bit_manipulation/print_binary/test_print_binary.py
class TestBits (line 4) | class TestBits(unittest.TestCase):
method test_print_binary (line 6) | def test_print_binary(self):
function main (line 19) | def main():
FILE: graphs_trees/bst/bst.py
class Node (line 1) | class Node(object):
method __init__ (line 3) | def __init__(self, data):
method __repr__ (line 9) | def __repr__(self):
class Bst (line 13) | class Bst(object):
method __init__ (line 15) | def __init__(self, root=None):
method insert (line 18) | def insert(self, data):
method _insert (line 27) | def _insert(self, node, data):
FILE: graphs_trees/bst/dfs.py
function in_order_traversal (line 1) | def in_order_traversal(node, visit_func):
function pre_order_traversal (line 7) | def pre_order_traversal(node, visit_func):
function post_order_traversal (line 13) | def post_order_traversal(node, visit_func):
FILE: graphs_trees/bst/test_bst.py
class TestTree (line 4) | class TestTree(unittest.TestCase):
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method test_tree_one (line 10) | def test_tree_one(self):
method test_tree_two (line 21) | def test_tree_two(self):
function main (line 34) | def main():
FILE: graphs_trees/bst_min/test_bst_min.py
function height (line 4) | def height(node):
class TestBstMin (line 11) | class TestBstMin(unittest.TestCase):
method test_bst_min (line 13) | def test_bst_min(self):
function main (line 27) | def main():
FILE: graphs_trees/bst_second_largest/test_bst_second_largest.py
class TestBstSecondLargest (line 4) | class TestBstSecondLargest(unittest.TestCase):
method test_bst_second_largest (line 6) | def test_bst_second_largest(self):
function main (line 30) | def main():
FILE: graphs_trees/bst_successor/test_bst_successor.py
class TestBstSuccessor (line 4) | class TestBstSuccessor(unittest.TestCase):
method test_bst_successor_empty (line 6) | def test_bst_successor_empty(self):
method test_bst_successor (line 10) | def test_bst_successor(self):
function main (line 36) | def main():
FILE: graphs_trees/bst_validate/test_bst_validate.py
class TestBstValidate (line 4) | class TestBstValidate(unittest.TestCase):
method test_bst_validate_empty (line 6) | def test_bst_validate_empty(self):
method test_bst_validate (line 10) | def test_bst_validate(self):
function main (line 31) | def main():
FILE: graphs_trees/check_balance/test_check_balance.py
class TestCheckBalance (line 4) | class TestCheckBalance(unittest.TestCase):
method test_check_balance_empty (line 6) | def test_check_balance_empty(self):
method test_check_balance (line 10) | def test_check_balance(self):
function main (line 39) | def main():
FILE: graphs_trees/graph/graph.py
class State (line 4) | class State(Enum):
class Node (line 11) | class Node:
method __init__ (line 13) | def __init__(self, key):
method __repr__ (line 20) | def __repr__(self):
method __lt__ (line 23) | def __lt__(self, other):
method add_neighbor (line 26) | def add_neighbor(self, neighbor, weight=0):
method remove_neighbor (line 33) | def remove_neighbor(self, neighbor):
class Graph (line 43) | class Graph:
method __init__ (line 45) | def __init__(self):
method add_node (line 48) | def add_node(self, key):
method add_edge (line 55) | def add_edge(self, source_key, dest_key, weight=0):
method add_undirected_edge (line 64) | def add_undirected_edge(self, src_key, dst_key, weight=0):
FILE: graphs_trees/graph/test_graph.py
class TestGraph (line 4) | class TestGraph(unittest.TestCase):
method create_graph (line 6) | def create_graph(self):
method test_graph (line 12) | def test_graph(self):
method test_graph_undirected (line 50) | def test_graph_undirected(self):
function main (line 66) | def main():
FILE: graphs_trees/graph_bfs/test_bfs.py
class TestBfs (line 4) | class TestBfs(unittest.TestCase):
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method test_bfs (line 10) | def test_bfs(self):
function main (line 29) | def main():
FILE: graphs_trees/graph_build_order/test_build_order.py
class TestBuildOrder (line 4) | class TestBuildOrder(unittest.TestCase):
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method test_build_order (line 19) | def test_build_order(self):
method test_build_order_circular (line 35) | def test_build_order_circular(self):
function main (line 44) | def main():
FILE: graphs_trees/graph_dfs/test_dfs.py
class TestDfs (line 4) | class TestDfs(unittest.TestCase):
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method test_dfs (line 10) | def test_dfs(self):
function main (line 29) | def main():
FILE: graphs_trees/graph_path_exists/test_path_exists.py
class TestPathExists (line 4) | class TestPathExists(unittest.TestCase):
method test_path_exists (line 6) | def test_path_exists(self):
function main (line 27) | def main():
FILE: graphs_trees/graph_shortest_path/priority_queue.py
class PriorityQueueNode (line 4) | class PriorityQueueNode(object):
method __init__ (line 6) | def __init__(self, obj, key):
method __repr__ (line 10) | def __repr__(self):
class PriorityQueue (line 14) | class PriorityQueue(object):
method __init__ (line 16) | def __init__(self):
method insert (line 19) | def insert(self, node):
method extract_min (line 25) | def extract_min(self):
method decrease_key (line 36) | def decrease_key(self, obj, new_key):
FILE: graphs_trees/graph_shortest_path/test_shortest_path.py
class TestShortestPath (line 4) | class TestShortestPath(unittest.TestCase):
method test_shortest_path (line 6) | def test_shortest_path(self):
function main (line 35) | def main():
FILE: graphs_trees/graph_shortest_path_unweighted/test_shortest_path.py
class TestShortestPath (line 4) | class TestShortestPath(unittest.TestCase):
method test_shortest_path (line 6) | def test_shortest_path(self):
function main (line 27) | def main():
FILE: graphs_trees/invert_tree/test_invert_tree.py
class TestInvertTree (line 4) | class TestInvertTree(unittest.TestCase):
method test_invert_tree (line 6) | def test_invert_tree(self):
function main (line 26) | def main():
FILE: graphs_trees/min_heap/min_heap.py
class MinHeap (line 6) | class MinHeap(object):
method __init__ (line 8) | def __init__(self):
method __len__ (line 11) | def __len__(self):
method extract_min (line 14) | def extract_min(self):
method peek_min (line 25) | def peek_min(self):
method insert (line 28) | def insert(self, key):
method _bubble_up (line 34) | def _bubble_up(self, index):
method _bubble_down (line 44) | def _bubble_down(self, index):
method _find_smaller_child (line 54) | def _find_smaller_child(self, index):
FILE: graphs_trees/min_heap/test_min_heap.py
class TestMinHeap (line 4) | class TestMinHeap(unittest.TestCase):
method test_min_heap (line 6) | def test_min_heap(self):
function main (line 44) | def main():
FILE: graphs_trees/tree_bfs/test_bfs.py
class TestBfs (line 4) | class TestBfs(unittest.TestCase):
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method test_bfs (line 10) | def test_bfs(self):
function main (line 22) | def main():
FILE: graphs_trees/tree_dfs/test_dfs.py
class TestDfs (line 4) | class TestDfs(unittest.TestCase):
method __init__ (line 6) | def __init__(self, *args, **kwargs):
method test_dfs (line 10) | def test_dfs(self):
function main (line 49) | def main():
FILE: graphs_trees/tree_height/height.py
class BstHeight (line 1) | class BstHeight(Bst):
method height (line 3) | def height(self, node):
FILE: graphs_trees/tree_height/test_height.py
class TestHeight (line 4) | class TestHeight(unittest.TestCase):
method test_height (line 6) | def test_height(self):
function main (line 18) | def main():
FILE: graphs_trees/tree_lca/test_lca.py
class TestLowestCommonAncestor (line 4) | class TestLowestCommonAncestor(unittest.TestCase):
method test_lca (line 6) | def test_lca(self):
function main (line 39) | def main():
FILE: graphs_trees/tree_level_lists/test_tree_level_lists.py
class TestTreeLevelLists (line 4) | class TestTreeLevelLists(unittest.TestCase):
method test_tree_level_lists (line 6) | def test_tree_level_lists(self):
function main (line 36) | def main():
FILE: graphs_trees/trie/test_trie.py
class TestTrie (line 4) | class TestTrie(unittest.TestCase):
method test_trie (line 6) | def test_trie(self):
method test_trie_remove_invalid (line 59) | def test_trie_remove_invalid(self):
function main (line 65) | def main():
FILE: graphs_trees/trie/trie.py
class Node (line 4) | class Node(object):
method __init__ (line 6) | def __init__(self, key, parent=None, terminates=False):
class Trie (line 13) | class Trie(object):
method __init__ (line 15) | def __init__(self):
method find (line 18) | def find(self, word):
method insert (line 29) | def insert(self, word):
method remove (line 42) | def remove(self, word):
method list_words (line 64) | def list_words(self):
method _list_words (line 70) | def _list_words(self, node, curr_word, result):
FILE: graphs_trees/utils/captured_output.py
function captured_output (line 7) | def captured_output():
FILE: graphs_trees/utils/results.py
class Results (line 1) | class Results(object):
method __init__ (line 3) | def __init__(self):
method add_result (line 6) | def add_result(self, result):
method clear_results (line 12) | def clear_results(self):
method __str__ (line 15) | def __str__(self):
FILE: linked_lists/add_reverse/test_add_reverse.py
class TestAddReverse (line 4) | class TestAddReverse(unittest.TestCase):
method test_add_reverse (line 6) | def test_add_reverse(self):
function main (line 42) | def main():
FILE: linked_lists/delete_mid/test_delete_mid.py
class TestDeleteNode (line 4) | class TestDeleteNode(unittest.TestCase):
method test_delete_node (line 6) | def test_delete_node(self):
function main (line 39) | def main():
FILE: linked_lists/find_loop_start/test_find_loop_start.py
class TestFindLoopStart (line 4) | class TestFindLoopStart(unittest.TestCase):
method test_find_loop_start (line 6) | def test_find_loop_start(self):
function main (line 43) | def main():
FILE: linked_lists/kth_to_last_elem/test_kth_to_last_elem.py
class Test (line 4) | class Test(unittest.TestCase):
method test_kth_to_last_elem (line 6) | def test_kth_to_last_elem(self):
function main (line 29) | def main():
FILE: linked_lists/linked_list/linked_list.py
class Node (line 1) | class Node(object):
method __init__ (line 3) | def __init__(self, data, next=None):
method __str__ (line 7) | def __str__(self):
class LinkedList (line 11) | class LinkedList(object):
method __init__ (line 13) | def __init__(self, head=None):
method __len__ (line 16) | def __len__(self):
method insert_to_front (line 24) | def insert_to_front(self, data):
method append (line 31) | def append(self, data):
method find (line 44) | def find(self, data):
method delete (line 54) | def delete(self, data):
method delete_alt (line 71) | def delete_alt(self, data):
method print_list (line 86) | def print_list(self):
method get_all_data (line 92) | def get_all_data(self):
FILE: linked_lists/linked_list/test_linked_list.py
class TestLinkedList (line 4) | class TestLinkedList(unittest.TestCase):
method test_insert_to_front (line 6) | def test_insert_to_front(self):
method test_append (line 23) | def test_append(self):
method test_find (line 40) | def test_find(self):
method test_delete (line 66) | def test_delete(self):
method test_len (line 92) | def test_len(self):
function main (line 107) | def main():
FILE: linked_lists/palindrome/test_palindrome.py
class TestPalindrome (line 4) | class TestPalindrome(unittest.TestCase):
method test_palindrome (line 6) | def test_palindrome(self):
function main (line 40) | def main():
FILE: linked_lists/partition/test_partition.py
class TestPartition (line 4) | class TestPartition(unittest.TestCase):
method test_partition (line 6) | def test_partition(self):
function main (line 42) | def main():
FILE: linked_lists/remove_duplicates/test_remove_duplicates.py
class TestRemoveDupes (line 4) | class TestRemoveDupes(unittest.TestCase):
method test_remove_dupes (line 6) | def test_remove_dupes(self, linked_list):
function main (line 34) | def main():
FILE: math_probability/add_digits/test_add_digits.py
class TestAddDigits (line 4) | class TestAddDigits(unittest.TestCase):
method test_add_digits (line 6) | def test_add_digits(self, func):
function main (line 16) | def main():
FILE: math_probability/check_prime/test_check_prime.py
class TestMath (line 4) | class TestMath(unittest.TestCase):
method test_check_prime (line 6) | def test_check_prime(self):
function main (line 16) | def main():
FILE: math_probability/generate_primes/test_generate_primes.py
class TestMath (line 4) | class TestMath(unittest.TestCase):
method test_generate_primes (line 6) | def test_generate_primes(self):
function main (line 20) | def main():
FILE: math_probability/math_ops/test_math_ops.py
class TestMathOps (line 4) | class TestMathOps(unittest.TestCase):
method test_math_ops (line 6) | def test_math_ops(self):
function main (line 27) | def main():
FILE: math_probability/power_two/test_is_power_of_two.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_is_power_of_two (line 6) | def test_is_power_of_two(self):
function main (line 17) | def main():
FILE: math_probability/sub_two/test_sub_two.py
class TestSubTwo (line 4) | class TestSubTwo(unittest.TestCase):
method test_sub_two (line 6) | def test_sub_two(self):
function main (line 16) | def main():
FILE: math_probability/sum_two/test_sum_two.py
class TestSumTwo (line 4) | class TestSumTwo(unittest.TestCase):
method test_sum_two (line 6) | def test_sum_two(self):
function main (line 15) | def main():
FILE: online_judges/assign_cookies/test_assign_cookie.py
class TestAssignCookie (line 4) | class TestAssignCookie(unittest.TestCase):
method test_assign_cookie (line 6) | def test_assign_cookie(self):
function main (line 18) | def main():
FILE: online_judges/busiest_period/test_find_busiest_period.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_find_busiest_period (line 6) | def test_find_busiest_period(self):
function main (line 22) | def main():
FILE: online_judges/island_perimeter/test_island_perimeter.py
class TestIslandPerimeter (line 4) | class TestIslandPerimeter(unittest.TestCase):
method test_island_perimeter (line 6) | def test_island_perimeter(self):
function main (line 21) | def main():
FILE: online_judges/license_key/test_format_license_key.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_format_license_key (line 6) | def test_format_license_key(self):
function main (line 23) | def main():
FILE: online_judges/longest_abs_file_path/test_length_longest_path.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_length_longest_path (line 6) | def test_length_longest_path(self):
function main (line 16) | def main():
FILE: online_judges/longest_substr_k_distinct/test_longest_substr.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_longest_substr (line 6) | def test_longest_substr(self):
function main (line 15) | def main():
FILE: online_judges/math_ops/test_math_ops.py
class TestMathOps (line 4) | class TestMathOps(unittest.TestCase):
method test_math_ops (line 6) | def test_math_ops(self):
function main (line 27) | def main():
FILE: online_judges/max_profit/test_max_profit.py
class TestMaxProfit (line 4) | class TestMaxProfit(unittest.TestCase):
method test_max_profit (line 6) | def test_max_profit(self):
function main (line 15) | def main():
FILE: online_judges/maximizing_xor/test_maximizing_xor.py
class TestMaximizingXor (line 4) | class TestMaximizingXor(unittest.TestCase):
method test_maximizing_xor (line 6) | def test_maximizing_xor(self):
function main (line 12) | def main():
FILE: online_judges/merge_ranges/test_merge_ranges.py
class TestMergeRanges (line 4) | class TestMergeRanges(unittest.TestCase):
method test_merge_ranges (line 6) | def test_merge_ranges(self):
function main (line 22) | def main():
FILE: online_judges/move_zeroes/test_move_zeroes.py
class TestMoveZeroes (line 4) | class TestMoveZeroes(unittest.TestCase):
method test_move_zeroes (line 6) | def test_move_zeroes(self):
function main (line 30) | def main():
FILE: online_judges/mult_other_numbers/test_mult_other_numbers.py
class TestMultOtherNumbers (line 4) | class TestMultOtherNumbers(unittest.TestCase):
method test_mult_other_numbers (line 6) | def test_mult_other_numbers(self):
function main (line 16) | def main():
FILE: online_judges/nim/test_can_win_nim.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_can_win_nim (line 6) | def test_can_win_nim(self):
function main (line 18) | def main():
FILE: online_judges/prod_three/test_prod_three.py
class TestProdThree (line 4) | class TestProdThree(unittest.TestCase):
method test_prod_three (line 6) | def test_prod_three(self):
function main (line 15) | def main():
FILE: online_judges/ransom_note/test_ransom_note.py
class TestRansomNote (line 4) | class TestRansomNote(unittest.TestCase):
method test_ransom_note (line 6) | def test_ransom_note(self):
function main (line 16) | def main():
FILE: online_judges/sentence_screen_fit/test_count_sentence_fit.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_count_sentence_fit (line 6) | def test_count_sentence_fit(self):
function main (line 27) | def main():
FILE: online_judges/str_diff/test_str_diff.py
class TestFindDiff (line 4) | class TestFindDiff(unittest.TestCase):
method test_find_diff (line 6) | def test_find_diff(self):
function main (line 13) | def main():
FILE: online_judges/sub_two/test_sub_two.py
class TestSubTwo (line 4) | class TestSubTwo(unittest.TestCase):
method test_sub_two (line 6) | def test_sub_two(self):
function main (line 16) | def main():
FILE: online_judges/sum_two/test_sum_two.py
class TestSumTwo (line 4) | class TestSumTwo(unittest.TestCase):
method test_sum_two (line 6) | def test_sum_two(self):
function main (line 15) | def main():
FILE: online_judges/utopian_tree/test_utopian_tree.py
class TestUtopianTree (line 4) | class TestUtopianTree(unittest.TestCase):
method test_utopian_tree (line 6) | def test_utopian_tree(self):
function main (line 14) | def main():
FILE: recursion_dynamic/coin_change/test_coin_change.py
class Challenge (line 4) | class Challenge(unittest.TestCase):
method test_coin_change (line 6) | def test_coin_change(self):
function main (line 14) | def main():
FILE: recursion_dynamic/coin_change_min/test_coin_change_min.py
class TestCoinChange (line 4) | class TestCoinChange(unittest.TestCase):
method test_coin_change (line 6) | def test_coin_change(self):
function main (line 16) | def main():
FILE: recursion_dynamic/coin_change_ways/test_coin_change_ways.py
class Challenge (line 4) | class Challenge(unittest.TestCase):
method test_coin_change_ways (line 6) | def test_coin_change_ways(self,solution):
function main (line 14) | def main():
FILE: recursion_dynamic/fibonacci/test_fibonacci.py
class TestFib (line 4) | class TestFib(unittest.TestCase):
method test_fib (line 6) | def test_fib(self, func):
function main (line 15) | def main():
FILE: recursion_dynamic/grid_path/test_grid_path.py
class TestGridPath (line 4) | class TestGridPath(unittest.TestCase):
method test_grid_path (line 6) | def test_grid_path(self):
function main (line 33) | def main():
FILE: recursion_dynamic/hanoi/test_hanoi.py
class TestHanoi (line 4) | class TestHanoi(unittest.TestCase):
method test_hanoi (line 6) | def test_hanoi(self):
function main (line 35) | def main():
FILE: recursion_dynamic/knapsack_01/test_knapsack.py
class TestKnapsack (line 4) | class TestKnapsack(unittest.TestCase):
method test_knapsack_bottom_up (line 6) | def test_knapsack_bottom_up(self):
method test_knapsack_top_down (line 26) | def test_knapsack_top_down(self):
function main (line 40) | def main():
FILE: recursion_dynamic/knapsack_unbounded/test_knapsack_unbounded.py
class TestKnapsack (line 4) | class TestKnapsack(unittest.TestCase):
method test_knapsack (line 6) | def test_knapsack(self):
function main (line 23) | def main():
FILE: recursion_dynamic/longest_common_subsequence/test_longest_common_subseq.py
class TestLongestCommonSubseq (line 4) | class TestLongestCommonSubseq(unittest.TestCase):
method test_longest_common_subseq (line 6) | def test_longest_common_subseq(self):
function main (line 17) | def main():
FILE: recursion_dynamic/longest_inc_subseq/test_longest_increasing_subseq.py
class TestLongestIncreasingSubseq (line 4) | class TestLongestIncreasingSubseq(unittest.TestCase):
method test_longest_increasing_subseq (line 6) | def test_longest_increasing_subseq(self):
function main (line 16) | def main():
FILE: recursion_dynamic/longest_substr_k_distinct/test_longest_substr.py
class TestSolution (line 4) | class TestSolution(unittest.TestCase):
method test_longest_substr (line 6) | def test_longest_substr(self):
function main (line 15) | def main():
FILE: recursion_dynamic/longest_substring/test_longest_common_substr.py
class TestLongestCommonSubstr (line 4) | class TestLongestCommonSubstr(unittest.TestCase):
method test_longest_common_substr (line 6) | def test_longest_common_substr(self):
function main (line 17) | def main():
FILE: recursion_dynamic/magic_index/test_find_magic_index.py
class TestFindMagicIndex (line 4) | class TestFindMagicIndex(unittest.TestCase):
method test_find_magic_index (line 6) | def test_find_magic_index(self):
function main (line 19) | def main():
FILE: recursion_dynamic/matrix_mult/test_find_min_cost.py
class TestMatrixMultiplicationCost (line 4) | class TestMatrixMultiplicationCost(unittest.TestCase):
method test_find_min_cost (line 6) | def test_find_min_cost(self):
function main (line 19) | def main():
FILE: recursion_dynamic/max_profit_k/test_max_profit.py
class TestMaxProfit (line 4) | class TestMaxProfit(unittest.TestCase):
method test_max_profit (line 6) | def test_max_profit(self):
function main (line 37) | def main():
FILE: recursion_dynamic/n_pairs_parentheses/test_n_pairs_parentheses.py
class TestPairParentheses (line 4) | class TestPairParentheses(unittest.TestCase):
method test_pair_parentheses (line 6) | def test_pair_parentheses(self):
function main (line 22) | def main():
FILE: recursion_dynamic/permutations/test_permutations.py
class TestPermutations (line 4) | class TestPermutations(unittest.TestCase):
method test_permutations (line 6) | def test_permutations(self):
function main (line 20) | def main():
FILE: recursion_dynamic/power_set/test_power_set.py
class TestPowerSet (line 4) | class TestPowerSet(unittest.TestCase):
method test_power_set (line 6) | def test_power_set(self):
method run_test (line 27) | def run_test(self, input_set, expected):
function main (line 33) | def main():
FILE: recursion_dynamic/steps/test_steps.py
class TestSteps (line 4) | class TestSteps(unittest.TestCase):
method test_steps (line 6) | def test_steps(self):
function main (line 19) | def main():
FILE: sorting_searching/anagrams/test_anagrams.py
class TestAnagrams (line 4) | class TestAnagrams(unittest.TestCase):
method test_group_anagrams (line 6) | def test_group_anagrams(self):
function main (line 16) | def main():
FILE: sorting_searching/insertion_sort/test_insertion_sort.py
class TestInsertionSort (line 4) | class TestInsertionSort(unittest.TestCase):
method test_insertion_sort (line 6) | def test_insertion_sort(self):
function main (line 25) | def main():
FILE: sorting_searching/merge_into/test_merge_into.py
class TestArray (line 4) | class TestArray(unittest.TestCase):
method test_merge_into (line 6) | def test_merge_into(self):
function main (line 21) | def main():
FILE: sorting_searching/merge_sort/test_merge_sort.py
class TestMergeSort (line 4) | class TestMergeSort(unittest.TestCase):
method test_merge_sort (line 6) | def test_merge_sort(self):
function main (line 25) | def main():
FILE: sorting_searching/new_int/test_new_int.py
class TestBits (line 4) | class TestBits(unittest.TestCase):
method test_new_int (line 6) | def test_new_int(self):
function main (line 19) | def main():
FILE: sorting_searching/quick_sort/test_quick_sort.py
class TestQuickSort (line 4) | class TestQuickSort(unittest.TestCase):
method test_quick_sort (line 6) | def test_quick_sort(self):
function main (line 25) | def main():
FILE: sorting_searching/radix_sort/test_radix_sort.py
class TestRadixSort (line 4) | class TestRadixSort(unittest.TestCase):
method test_sort (line 6) | def test_sort(self):
function main (line 16) | def main():
FILE: sorting_searching/rotated_array_search/test_search_sorted_array.py
class TestArray (line 4) | class TestArray(unittest.TestCase):
method test_search_sorted_array (line 6) | def test_search_sorted_array(self):
function main (line 18) | def main():
FILE: sorting_searching/search_sorted_matrix/test_search_sorted_matrix.py
class TestSortedMatrix (line 4) | class TestSortedMatrix(unittest.TestCase):
method test_find_val (line 6) | def test_find_val(self):
function main (line 18) | def main():
FILE: sorting_searching/selection_sort/test_selection_sort.py
class TestSelectionSort (line 4) | class TestSelectionSort(unittest.TestCase):
method test_selection_sort (line 6) | def test_selection_sort(self, func):
function main (line 23) | def main():
FILE: stacks_queues/n_stacks/test_n_stacks.py
class TestStacks (line 4) | class TestStacks(unittest.TestCase):
method test_pop_on_empty (line 6) | def test_pop_on_empty(self, num_stacks, stack_size):
method test_push_on_full (line 11) | def test_push_on_full(self, num_stacks, stack_size):
method test_stacks (line 18) | def test_stacks(self, num_stacks, stack_size):
function main (line 35) | def main():
FILE: stacks_queues/queue_from_stacks/test_queue_from_stacks.py
class TestQueueFromStacks (line 4) | class TestQueueFromStacks(unittest.TestCase):
method test_queue_from_stacks (line 6) | def test_queue_from_stacks(self):
function main (line 33) | def main():
FILE: stacks_queues/queue_list/queue_list.py
class Node (line 1) | class Node(object):
method __init__ (line 3) | def __init__(self, data):
class Queue (line 8) | class Queue(object):
method __init__ (line 10) | def __init__(self):
method enqueue (line 14) | def enqueue(self, data):
method dequeue (line 24) | def dequeue(self):
FILE: stacks_queues/queue_list/test_queue_list.py
class TestQueue (line 4) | class TestQueue(unittest.TestCase):
method test_end_to_end (line 8) | def test_end_to_end(self):
function main (line 32) | def main():
FILE: stacks_queues/set_of_stacks/test_set_of_stacks.py
class TestSetOfStacks (line 4) | class TestSetOfStacks(unittest.TestCase):
method test_set_of_stacks (line 6) | def test_set_of_stacks(self):
function main (line 30) | def main():
FILE: stacks_queues/sort_stack/test_sort_stack.py
class TestSortStack (line 5) | class TestSortStack(unittest.TestCase):
method get_sorted_stack (line 7) | def get_sorted_stack(self, stack, numbers):
method test_sort_stack (line 13) | def test_sort_stack(self, stack):
function main (line 34) | def main():
FILE: stacks_queues/stack/stack.py
class Node (line 1) | class Node(object):
method __init__ (line 3) | def __init__(self, data, next=None):
class Stack (line 8) | class Stack(object):
method __init__ (line 10) | def __init__(self, top=None):
method push (line 13) | def push(self, data):
method pop (line 16) | def pop(self):
method peek (line 23) | def peek(self):
method is_empty (line 26) | def is_empty(self):
FILE: stacks_queues/stack/test_stack.py
class TestStack (line 4) | class TestStack(unittest.TestCase):
method test_end_to_end (line 8) | def test_end_to_end(self):
function main (line 37) | def main():
FILE: stacks_queues/stack_min/test_stack_min.py
class TestStackMin (line 4) | class TestStackMin(unittest.TestCase):
method test_stack_min (line 6) | def test_stack_min(self):
function main (line 38) | def main():
FILE: staging/arrays_strings/reverse_words/reverse_words_solution.py
class TestReverseWords (line 4) | class TestReverseWords(unittest.TestCase):
method testReverseWords (line 6) | def testReverseWords(self, func):
function main (line 14) | def main():
FILE: staging/graphs_trees/binary_tree/binary_search_tree.py
class Node (line 2) | class Node (object):
method __init__ (line 3) | def __init__ (self, data):
class BinaryTree (line 8) | class BinaryTree (object):
method __init__ (line 9) | def __init__ (self):
method insert (line 12) | def insert (self, newData):
method delete (line 33) | def delete (self, data):
method minNode (line 101) | def minNode (self):
method maxNode (line 108) | def maxNode (self):
method printPostOrder (line 115) | def printPostOrder (self):
method printInOrder (line 128) | def printInOrder (self):
method printPreOrder (line 141) | def printPreOrder (self):
method treeIsEmpty (line 154) | def treeIsEmpty (self):
FILE: staging/graphs_trees/binary_tree/test_binary_search_tree.py
class TestBinaryTree (line 3) | class TestBinaryTree(unittest.TestCase):
method test_insert_traversals (line 5) | def test_insert_traversals (self):
method test_max_min_nodes (line 34) | def test_max_min_nodes (self):
method test_delete (line 54) | def test_delete (self):
function main (line 73) | def main():
FILE: staging/sorting_searching/group_ordered/test_group_ordered.py
class TestGroupOrdered (line 4) | class TestGroupOrdered(unittest.TestCase):
method test_group_ordered (line 5) | def test_group_ordered(self, func):
function main (line 20) | def main():
FILE: templates/test_foo.py
class TestFoo (line 4) | class TestFoo(unittest.TestCase):
method test_foo (line 6) | def test_foo(self):
function main (line 13) | def main():
Condensed preview — 499 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,734K chars).
[
{
"path": ".gitattributes",
"chars": 33,
"preview": "*.ipynb linguist-language=Python\n"
},
{
"path": ".gitignore",
"chars": 793,
"preview": "# Byte-compiled / optimized / DLL files\n__pycache__/\n*.py[cod]\n\n# C extensions\n*.so\n\n# Distribution / packaging\n.Python\n"
},
{
"path": "CONTRIBUTING.md",
"chars": 5657,
"preview": "Contributing\n============\n\nContributions are welcome!\n\n**Please carefully read this page to make the code review process"
},
{
"path": "LICENSE",
"chars": 775,
"preview": "I am providing code and resources in this repository to you under an open source\nlicense. Because this is my personal r"
},
{
"path": "README.md",
"chars": 66877,
"preview": "<br/>\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/donnemartin/interactive-coding-challenges/master/"
},
{
"path": "__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/compress/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/compress/compress_challenge.ipynb",
"chars": 4240,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/compress/compress_solution.ipynb",
"chars": 5274,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/compress/test_compress.py",
"chars": 608,
"preview": "import unittest\n\n\nclass TestCompress(unittest.TestCase):\n\n def test_compress(self, func):\n self.assertEqual(fu"
},
{
"path": "arrays_strings/compress_alt/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/compress_alt/better_compress_challenge.ipynb",
"chars": 4205,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [hash"
},
{
"path": "arrays_strings/compress_alt/better_compress_solution.ipynb",
"chars": 9330,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [hash"
},
{
"path": "arrays_strings/compress_alt/test_compress.py",
"chars": 603,
"preview": "import unittest\n\n\nclass TestCompress(unittest.TestCase):\n\n def test_compress(self, func):\n self.assertEqual(fu"
},
{
"path": "arrays_strings/fizz_buzz/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/fizz_buzz/fizz_buzz_challenge.ipynb",
"chars": 4751,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/fizz_buzz/fizz_buzz_solution.ipynb",
"chars": 5439,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/fizz_buzz/test_fizz_buzz.py",
"chars": 761,
"preview": "import unittest\n\n\nclass TestFizzBuzz(unittest.TestCase):\n\n def test_fizz_buzz(self):\n solution = Solution()\n "
},
{
"path": "arrays_strings/hash_map/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/hash_map/hash_map_challenge.ipynb",
"chars": 6023,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/hash_map/hash_map_solution.ipynb",
"chars": 7575,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/hash_map/test_hash_map.py",
"chars": 1438,
"preview": "import unittest\n\n\nclass TestHashMap(unittest.TestCase):\n\n # TODO: It would be better if we had unit tests for each\n "
},
{
"path": "arrays_strings/permutation/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/permutation/permutation_challenge.ipynb",
"chars": 4694,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/permutation/permutation_solution.ipynb",
"chars": 7145,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/permutation/test_permutation_solution.py",
"chars": 855,
"preview": "import unittest\n\n\nclass TestPermutation(unittest.TestCase):\n\n def test_permutation(self, func):\n self.assertEq"
},
{
"path": "arrays_strings/priority_queue/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/priority_queue/priority_queue.py",
"chars": 932,
"preview": "import sys\n\n\nclass PriorityQueueNode(object):\n\n def __init__(self, obj, key):\n self.obj = obj\n self.key"
},
{
"path": "arrays_strings/priority_queue/priority_queue_challenge.ipynb",
"chars": 5277,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/priority_queue/priority_queue_solution.ipynb",
"chars": 6516,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/priority_queue/test_priority_queue.py",
"chars": 958,
"preview": "import unittest\n\n\nclass TestPriorityQueue(unittest.TestCase):\n\n def test_priority_queue(self):\n priority_queue"
},
{
"path": "arrays_strings/reverse_string/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/reverse_string/reverse_string.cpp",
"chars": 654,
"preview": "#include <stdio.h>\n\nvoid Reverse(char* str) {\n if (str) {\n char* i = str;\t// first letter\n char* j = st"
},
{
"path": "arrays_strings/reverse_string/reverse_string_challenge.ipynb",
"chars": 4568,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/reverse_string/reverse_string_solution.ipynb",
"chars": 7802,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/reverse_string/test_reverse_string.py",
"chars": 811,
"preview": "import unittest\n\n\nclass TestReverse(unittest.TestCase):\n\n def test_reverse(self, func):\n self.assertEqual(func"
},
{
"path": "arrays_strings/rotation/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/rotation/rotation_challenge.ipynb",
"chars": 4487,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/rotation/rotation_solution.ipynb",
"chars": 4495,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/rotation/test_rotation.py",
"chars": 599,
"preview": "import unittest\n\n\nclass TestRotation(unittest.TestCase):\n\n def test_rotation(self):\n rotation = Rotation()\n "
},
{
"path": "arrays_strings/str_diff/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/str_diff/str_diff_challenge.ipynb",
"chars": 4445,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/str_diff/str_diff_solution.ipynb",
"chars": 5796,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/str_diff/test_str_diff.py",
"chars": 880,
"preview": "import unittest\n\n\nclass TestFindDiff(unittest.TestCase):\n\n def test_find_diff(self):\n solution = Solution()\n "
},
{
"path": "arrays_strings/two_sum/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/two_sum/test_two_sum.py",
"chars": 529,
"preview": "import unittest\n\n\nclass TestTwoSum(unittest.TestCase):\n\n def test_two_sum(self):\n solution = Solution()\n "
},
{
"path": "arrays_strings/two_sum/two_sum_challenge.ipynb",
"chars": 3890,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/two_sum/two_sum_solution.ipynb",
"chars": 6022,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/unique_chars/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "arrays_strings/unique_chars/test_unique_chars.py",
"chars": 849,
"preview": "import unittest\n\n\nclass TestUniqueChars(unittest.TestCase):\n\n def test_unique_chars(self, func):\n self.assertE"
},
{
"path": "arrays_strings/unique_chars/unique_chars_challenge.ipynb",
"chars": 4516,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "arrays_strings/unique_chars/unique_chars_solution.ipynb",
"chars": 7574,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/bit/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/bit/bit_challenge.ipynb",
"chars": 6001,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/bit/bit_solution.ipynb",
"chars": 9886,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/bit/test_bit.py",
"chars": 1208,
"preview": "import unittest\n\n\nclass TestBit(unittest.TestCase):\n\n def test_bit(self):\n number = int('10001110', base=2)\n "
},
{
"path": "bit_manipulation/bits_to_flip/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/bits_to_flip/bits_to_flip_challenge.ipynb",
"chars": 3737,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/bits_to_flip/bits_to_flip_solution.ipynb",
"chars": 4287,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/bits_to_flip/test_bits_to_flip.py",
"chars": 405,
"preview": "import unittest\n\n\nclass TestBits(unittest.TestCase):\n\n def test_bits_to_flip(self):\n bits = Bits()\n a ="
},
{
"path": "bit_manipulation/draw_line/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/draw_line/draw_line_challenge.ipynb",
"chars": 4580,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/draw_line/draw_line_solution.ipynb",
"chars": 8053,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/draw_line/test_draw_line.py",
"chars": 863,
"preview": "import unittest\n\n\nclass TestBitsScreen(unittest.TestCase):\n\n def test_draw_line(self):\n bits_screen = BitsScre"
},
{
"path": "bit_manipulation/flip_bit/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/flip_bit/flip_bit_challenge.ipynb",
"chars": 4400,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/flip_bit/flip_bit_solution.ipynb",
"chars": 7946,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/flip_bit/test_flip_bit.py",
"chars": 829,
"preview": "import unittest\n\n\nclass TestBits(unittest.TestCase):\n\n def test_flip_bit(self):\n bits = Bits()\n self.as"
},
{
"path": "bit_manipulation/get_next/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/get_next/get_next_challenge.ipynb",
"chars": 4702,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/get_next/get_next_solution.ipynb",
"chars": 8474,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/get_next/test_get_next_largest.py",
"chars": 1095,
"preview": "import unittest\n\n\nclass TestBits(unittest.TestCase):\n\n def test_get_next_largest(self):\n bits = Bits()\n "
},
{
"path": "bit_manipulation/insert_m_into_n/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/insert_m_into_n/insert_m_into_n_challenge.ipynb",
"chars": 3926,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/insert_m_into_n/insert_m_into_n_solution.ipynb",
"chars": 5317,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/insert_m_into_n/test_insert_m_into_n.py",
"chars": 477,
"preview": "import unittest\n\n\nclass TestBit(unittest.TestCase):\n\n def test_insert_m_into_n(self):\n n = int('00000100001111"
},
{
"path": "bit_manipulation/pairwise_swap/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/pairwise_swap/pairwise_swap_challenge.ipynb",
"chars": 3910,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/pairwise_swap/pairwise_swap_solution.ipynb",
"chars": 5109,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/pairwise_swap/test_pairwise_swap.py",
"chars": 592,
"preview": "import unittest\n\n\nclass TestBits(unittest.TestCase):\n\n def test_pairwise_swap(self):\n bits = Bits()\n se"
},
{
"path": "bit_manipulation/print_binary/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "bit_manipulation/print_binary/print_binary_challenge.ipynb",
"chars": 4171,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/print_binary/print_binary_solution.ipynb",
"chars": 5030,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "bit_manipulation/print_binary/test_print_binary.py",
"chars": 613,
"preview": "import unittest\n\n\nclass TestBits(unittest.TestCase):\n\n def test_print_binary(self):\n bit = Bits()\n self"
},
{
"path": "graphs_trees/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/bst/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/bst/bst.py",
"chars": 1166,
"preview": "class Node(object):\n\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right "
},
{
"path": "graphs_trees/bst/bst_challenge.ipynb",
"chars": 5429,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst/bst_solution.ipynb",
"chars": 7283,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst/dfs.py",
"chars": 604,
"preview": "def in_order_traversal(node, visit_func):\n if node is not None:\n in_order_traversal(node.left, visit_func)\n "
},
{
"path": "graphs_trees/bst/test_bst.py",
"chars": 939,
"preview": "import unittest\n\n\nclass TestTree(unittest.TestCase):\n\n def __init__(self, *args, **kwargs):\n super(TestTree, s"
},
{
"path": "graphs_trees/bst_min/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/bst_min/bst_min_challenge.ipynb",
"chars": 4412,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_min/bst_min_solution.ipynb",
"chars": 5229,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_min/test_bst_min.py",
"chars": 669,
"preview": "import unittest\n\n\ndef height(node):\n if node is None:\n return 0\n return 1 + max(height(node.left),\n "
},
{
"path": "graphs_trees/bst_second_largest/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/bst_second_largest/bst_second_largest_challenge.ipynb",
"chars": 5343,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_second_largest/bst_second_largest_solution.ipynb",
"chars": 6766,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_second_largest/test_bst_second_largest.py",
"chars": 962,
"preview": "import unittest\n\n\nclass TestBstSecondLargest(unittest.TestCase):\n\n def test_bst_second_largest(self):\n bst = S"
},
{
"path": "graphs_trees/bst_successor/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/bst_successor/bst_successor_challenge.ipynb",
"chars": 5460,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_successor/bst_successor_solution.ipynb",
"chars": 6378,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_successor/test_bst_successor.py",
"chars": 1192,
"preview": "import unittest\n\n\nclass TestBstSuccessor(unittest.TestCase):\n\n def test_bst_successor_empty(self):\n bst_succes"
},
{
"path": "graphs_trees/bst_validate/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/bst_validate/bst_validate_challenge.ipynb",
"chars": 4875,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_validate/bst_validate_solution.ipynb",
"chars": 5655,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/bst_validate/test_bst_validate.py",
"chars": 857,
"preview": "import unittest\n\n\nclass TestBstValidate(unittest.TestCase):\n\n def test_bst_validate_empty(self):\n bst = BstVal"
},
{
"path": "graphs_trees/check_balance/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/check_balance/check_balance_challenge.ipynb",
"chars": 5037,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/check_balance/check_balance_solution.ipynb",
"chars": 6042,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/check_balance/test_check_balance.py",
"chars": 1043,
"preview": "import unittest\n\n\nclass TestCheckBalance(unittest.TestCase):\n\n def test_check_balance_empty(self):\n bst = BstB"
},
{
"path": "graphs_trees/graph/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph/graph.py",
"chars": 2079,
"preview": "from enum import Enum # Python 2 users: Run pip install enum34\n\n\nclass State(Enum):\n\n unvisited = 0\n visiting = 1"
},
{
"path": "graphs_trees/graph/graph_challenge.ipynb",
"chars": 8873,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph/graph_solution.ipynb",
"chars": 11719,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph/test_graph.py",
"chars": 2840,
"preview": "import unittest\n\n\nclass TestGraph(unittest.TestCase):\n\n def create_graph(self):\n graph = Graph()\n for k"
},
{
"path": "graphs_trees/graph_bfs/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph_bfs/bfs_challenge.ipynb",
"chars": 5008,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_bfs/bfs_solution.ipynb",
"chars": 6245,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_bfs/test_bfs.py",
"chars": 820,
"preview": "import unittest\n\n\nclass TestBfs(unittest.TestCase):\n\n def __init__(self, *args, **kwargs):\n super(TestBfs, sel"
},
{
"path": "graphs_trees/graph_build_order/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph_build_order/build_order_challenge.ipynb",
"chars": 6479,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_build_order/build_order_solution.ipynb",
"chars": 8562,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_build_order/test_build_order.py",
"chars": 1633,
"preview": "import unittest\n\n\nclass TestBuildOrder(unittest.TestCase):\n\n def __init__(self, *args, **kwargs):\n super(TestB"
},
{
"path": "graphs_trees/graph_dfs/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph_dfs/dfs_challenge.ipynb",
"chars": 5169,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_dfs/dfs_solution.ipynb",
"chars": 5407,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_dfs/test_dfs.py",
"chars": 820,
"preview": "import unittest\n\n\nclass TestDfs(unittest.TestCase):\n\n def __init__(self, *args, **kwargs):\n super(TestDfs, sel"
},
{
"path": "graphs_trees/graph_path_exists/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph_path_exists/path_exists_challenge.ipynb",
"chars": 5157,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_path_exists/path_exists_solution.ipynb",
"chars": 6270,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_path_exists/test_path_exists.py",
"chars": 843,
"preview": "import unittest\n\n\nclass TestPathExists(unittest.TestCase):\n\n def test_path_exists(self):\n nodes = []\n g"
},
{
"path": "graphs_trees/graph_shortest_path/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph_shortest_path/graph_shortest_path_challenge.ipynb",
"chars": 7555,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_shortest_path/graph_shortest_path_solution.ipynb",
"chars": 12334,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_shortest_path/priority_queue.py",
"chars": 957,
"preview": "import sys\n\n\nclass PriorityQueueNode(object):\n\n def __init__(self, obj, key):\n self.obj = obj\n self.key"
},
{
"path": "graphs_trees/graph_shortest_path/test_shortest_path.py",
"chars": 1321,
"preview": "import unittest\n\n\nclass TestShortestPath(unittest.TestCase):\n\n def test_shortest_path(self):\n graph = Graph()\n"
},
{
"path": "graphs_trees/graph_shortest_path_unweighted/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/graph_shortest_path_unweighted/shortest_path_challenge.ipynb",
"chars": 5446,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_shortest_path_unweighted/shortest_path_solution.ipynb",
"chars": 7558,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/graph_shortest_path_unweighted/test_shortest_path.py",
"chars": 867,
"preview": "import unittest\n\n\nclass TestShortestPath(unittest.TestCase):\n\n def test_shortest_path(self):\n nodes = []\n "
},
{
"path": "graphs_trees/invert_tree/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/invert_tree/invert_tree_challenge.ipynb",
"chars": 4604,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/invert_tree/invert_tree_solution.ipynb",
"chars": 5015,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/invert_tree/test_invert_tree.py",
"chars": 848,
"preview": "import unittest\n\n\nclass TestInvertTree(unittest.TestCase):\n\n def test_invert_tree(self):\n root = Node(5)\n "
},
{
"path": "graphs_trees/min_heap/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/min_heap/min_heap.py",
"chars": 2192,
"preview": "from __future__ import division\n\nimport sys\n\n\nclass MinHeap(object):\n\n def __init__(self):\n self.array = []\n\n "
},
{
"path": "graphs_trees/min_heap/min_heap_challenge.ipynb",
"chars": 5227,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/min_heap/min_heap_solution.ipynb",
"chars": 11008,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/min_heap/test_min_heap.py",
"chars": 1563,
"preview": "import unittest\n\n\nclass TestMinHeap(unittest.TestCase):\n\n def test_min_heap(self):\n heap = MinHeap()\n s"
},
{
"path": "graphs_trees/tree_bfs/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/tree_bfs/bfs_challenge.ipynb",
"chars": 4189,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_bfs/bfs_solution.ipynb",
"chars": 4626,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_bfs/test_bfs.py",
"chars": 545,
"preview": "import unittest\n\n\nclass TestBfs(unittest.TestCase):\n\n def __init__(self, *args, **kwargs):\n super(TestBfs, sel"
},
{
"path": "graphs_trees/tree_dfs/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/tree_dfs/dfs_challenge.ipynb",
"chars": 6010,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_dfs/dfs_solution.ipynb",
"chars": 7438,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_dfs/test_dfs.py",
"chars": 1531,
"preview": "import unittest\n\n\nclass TestDfs(unittest.TestCase):\n\n def __init__(self, *args, **kwargs):\n super(TestDfs, sel"
},
{
"path": "graphs_trees/tree_height/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/tree_height/height.py",
"chars": 191,
"preview": "class BstHeight(Bst):\n\n def height(self, node):\n if node is None:\n return 0\n return 1 + max("
},
{
"path": "graphs_trees/tree_height/height_challenge.ipynb",
"chars": 3978,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_height/height_solution.ipynb",
"chars": 3876,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_height/test_height.py",
"chars": 444,
"preview": "import unittest\n\n\nclass TestHeight(unittest.TestCase):\n\n def test_height(self):\n bst = BstHeight(Node(5))\n "
},
{
"path": "graphs_trees/tree_lca/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/tree_lca/test_lca.py",
"chars": 1312,
"preview": "import unittest\n\n\nclass TestLowestCommonAncestor(unittest.TestCase):\n\n def test_lca(self):\n node10 = Node(10)\n"
},
{
"path": "graphs_trees/tree_lca/tree_lca_challenge.ipynb",
"chars": 5487,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_lca/tree_lca_solution.ipynb",
"chars": 8657,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_level_lists/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/tree_level_lists/test_tree_level_lists.py",
"chars": 1062,
"preview": "import unittest\n\n\nclass TestTreeLevelLists(unittest.TestCase):\n\n def test_tree_level_lists(self):\n bst = BstLe"
},
{
"path": "graphs_trees/tree_level_lists/tree_level_lists_challenge.ipynb",
"chars": 5211,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/tree_level_lists/tree_level_lists_solution.ipynb",
"chars": 6088,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/trie/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/trie/test_trie.py",
"chars": 2160,
"preview": "import unittest\n\n\nclass TestTrie(unittest.TestCase): \n\n def test_trie(self):\n trie = Trie()\n\n pri"
},
{
"path": "graphs_trees/trie/trie.py",
"chars": 2321,
"preview": "from collections import OrderedDict\n\n\nclass Node(object):\n\n def __init__(self, key, parent=None, terminates=False):\n "
},
{
"path": "graphs_trees/trie/trie_challenge.ipynb",
"chars": 7541,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/trie/trie_solution.ipynb",
"chars": 12375,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "graphs_trees/utils/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "graphs_trees/utils/captured_output.py",
"chars": 370,
"preview": "import sys\nfrom contextlib import contextmanager\nfrom StringIO import StringIO\n\n\n@contextmanager\ndef captured_output():\n"
},
{
"path": "graphs_trees/utils/results.py",
"chars": 406,
"preview": "class Results(object):\n\n def __init__(self):\n self.results = []\n\n def add_result(self, result):\n # T"
},
{
"path": "linked_lists/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "linked_lists/add_reverse/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "linked_lists/add_reverse/add_reverse_challenge.ipynb",
"chars": 5952,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/add_reverse/add_reverse_solution.ipynb",
"chars": 7643,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/add_reverse/test_add_reverse.py",
"chars": 1482,
"preview": "import unittest\n\n\nclass TestAddReverse(unittest.TestCase):\n\n def test_add_reverse(self):\n print('Test: Empty l"
},
{
"path": "linked_lists/delete_mid/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "linked_lists/delete_mid/delete_mid_challenge.ipynb",
"chars": 5398,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/delete_mid/delete_mid_solution.ipynb",
"chars": 5633,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/delete_mid/test_delete_mid.py",
"chars": 1402,
"preview": "import unittest\n\n\nclass TestDeleteNode(unittest.TestCase):\n\n def test_delete_node(self):\n print('Test: Empty l"
},
{
"path": "linked_lists/find_loop_start/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "linked_lists/find_loop_start/find_loop_start_challenge.ipynb",
"chars": 5583,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/find_loop_start/find_loop_start_solution.ipynb",
"chars": 6484,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/find_loop_start/test_find_loop_start.py",
"chars": 1440,
"preview": "import unittest\n\n\nclass TestFindLoopStart(unittest.TestCase):\n\n def test_find_loop_start(self):\n print('Test: "
},
{
"path": "linked_lists/kth_to_last_elem/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "linked_lists/kth_to_last_elem/kth_to_last_elem_challenge.ipynb",
"chars": 5097,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/kth_to_last_elem/kth_to_last_elem_solution.ipynb",
"chars": 5651,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"metadata\": {},\n \"source\": [\n \"This notebook was prepared by [Donn"
},
{
"path": "linked_lists/kth_to_last_elem/test_kth_to_last_elem.py",
"chars": 907,
"preview": "import unittest\n\n\nclass Test(unittest.TestCase):\n\n def test_kth_to_last_elem(self):\n print('Test: Empty list')"
},
{
"path": "linked_lists/linked_list/__init__.py",
"chars": 0,
"preview": ""
},
{
"path": "linked_lists/linked_list/linked_list.py",
"chars": 2549,
"preview": "class Node(object):\n\n def __init__(self, data, next=None):\n self.next = next\n self.data = data\n\n def"
}
]
// ... and 299 more files (download for full content)
About this extraction
This page contains the full source code of the donnemartin/interactive-coding-challenges GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 499 files (1.5 MB), approximately 470.1k tokens, and a symbol index with 479 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.