From 4b1fe33f96b2aba6508632a2a8f95dbdfac93214 Mon Sep 17 00:00:00 2001 From: Mari Wahl Date: Tue, 6 Jan 2015 00:49:32 -0500 Subject: [PATCH] glassdoor 2014 --- .../2014}/abstract_strucutres/HashTable.py | 0 .../abstract_strucutres/queue_with_stack.py | 0 .../stack_with_minumum.txt | 0 .../2014}/advanced/lru_cache.py | 0 .../2014}/basic_examples/example_args.py | 0 .../example_benchmark_decorator.py | 0 .../basic_examples/example_comp_lists.py | 0 .../2014}/basic_examples/example_generator.py | 0 .../2014}/basic_examples/example_lambda.py | 0 .../2014}/basic_examples/example_logging.py | 0 .../2014}/basic_examples/example_queue.py | 0 .../2014}/basic_examples/example_socket.py | 0 .../basic_examples/example_string_format.py | 0 .../2014}/basic_examples/example_telnet.py | 0 .../2014}/basic_examples/example_testing.py | 0 .../2014}/basic_examples/example_threads.py | 0 .../2014}/basic_examples/export_pickle.py | 0 .../2014}/basic_examples/import_pickle.py | 0 .../{ => glassdoor/2014}/bitwise/bitwise.txt | 0 .../2014}/bitwise/clear_bits.py | 0 .../2014}/bitwise/find_bit_len.py | 0 .../{ => glassdoor/2014}/bitwise/get_bit.py | 0 .../bitwise/num_bits_to_convert_2_nums.py | 0 .../{ => glassdoor/2014}/bitwise/set_bit.py | 0 .../2014}/bitwise/swap_in_place.py | 0 .../2014}/bitwise/update_bit.py | 0 .../2014}/design/design_pattern.txt | 0 .../2014}/design/design_text_editor.txt | 0 .../2014}/design/example_decorator.py | 0 .../anagrams_hash_table.txt | 0 .../2014}/math_arrays_and_strings/balance.txt | 0 .../check_2_numbers_array_sum.py | 0 .../check_if_anagrams.py | 0 .../check_palindrome.py | 0 .../decide_if_permutation.py | 0 .../delete_duplicate_char_str.py | 0 .../math_arrays_and_strings/fibonacci.py | 3 +- .../find_all_permutations_string.py | 0 .../find_combinations_strings.py | 0 .../find_if_is_substr.py | 0 .../find_if_unique_char.py | 0 .../find_largest_sum.py | 0 .../find_non_repeating_number.py | 0 .../math_arrays_and_strings/find_sum_ints.py | 0 .../math_arrays_and_strings/finding_gcd.py | 0 .../finding_if_prime.py | 0 .../math_arrays_and_strings/generate_prime.py | 0 .../get_float_rep_bin.py | 0 .../interserction_two_arrays.py | 0 .../max_subarray_stocks.py | 0 .../number_of_zeros_factorial.txt | 0 .../prod_other_ints.py | 0 .../math_arrays_and_strings/ransom_note.py | 0 .../math_arrays_and_strings/rev_string.py | 0 .../math_arrays_and_strings/reverse_words.py | 0 .../reverse_words_sentence.py | 0 .../sorting_and_searching/deck_shuffling.txt | 0 .../2014}/sorting_and_searching/quick_sort.py | 0 .../2014}/trees_paths/binary_search_tree.py | 0 .../2014}/trees_paths/binary_tree.py | 0 .../2014}/trees_paths/check_whether_bst.py | 0 .../trees_paths/lowest_common_ancestor.py | 0 .../trees_paths/transversal_BST_ancestor.py | 0 .../glassdoor/2015/alpha_permutation.py | 34 +++++++++++ .../glassdoor/2015/anagram.py | 31 ++++++++++ .../glassdoor/2015/anagram_sorting.py | 11 ---- .../glassdoor/2015/bucket.py | 19 ------- ...s.py => check_if_3_numbers_sum_to_zero.py} | 0 .../2015/{tree.py => check_if_bst.py} | 0 .../{palindrome.py => check_if_palindrome.py} | 1 - ....py => check_non_overlapping_intervals.py} | 0 .../glassdoor/2015/comb.py | 11 ---- .../{pairs.py => find_if_numbers_sum_to_k.py} | 0 .../2015/find_longest_str_unique_chars.py | 35 ++++++++++++ .../2015/{fib.py => find_nth_fibonacci.py} | 22 ++++++++ .../glassdoor/2015/find_prime_factors.py | 34 +++++++++++ .../glassdoor/2015/long_string.py | 12 ---- .../glassdoor/2015/longest_common_prefix.py | 38 +++++++++++++ .../glassdoor/2015/longest_str.py | 11 ---- ...{merge.py => merge_and_sort_two_arrays.py} | 0 .../glassdoor/2015/permutations.py | 23 +++++--- .../glassdoor/2015/primes.py | 11 ---- .../glassdoor/2015/rec_bt.py | 12 ---- .../glassdoor/2015/smallest_bst.py | 11 ---- ...m_str.py => sum_two_numbers_as_strings.py} | 0 .../glassdoor/2015/transversing_bt.py | 50 +++++++++++++++++ .../glassdoor/2015/trie.py | 56 ++++++++++++++++++- 87 files changed, 313 insertions(+), 112 deletions(-) rename src/extra_interview_problems/{ => glassdoor/2014}/abstract_strucutres/HashTable.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/abstract_strucutres/queue_with_stack.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/abstract_strucutres/stack_with_minumum.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/advanced/lru_cache.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_args.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_benchmark_decorator.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_comp_lists.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_generator.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_lambda.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_logging.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_queue.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_socket.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_string_format.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_telnet.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_testing.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/example_threads.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/export_pickle.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/basic_examples/import_pickle.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/bitwise.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/clear_bits.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/find_bit_len.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/get_bit.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/num_bits_to_convert_2_nums.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/set_bit.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/swap_in_place.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/bitwise/update_bit.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/design/design_pattern.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/design/design_text_editor.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/design/example_decorator.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/anagrams_hash_table.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/balance.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/check_2_numbers_array_sum.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/check_if_anagrams.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/check_palindrome.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/decide_if_permutation.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/delete_duplicate_char_str.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/fibonacci.py (82%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_all_permutations_string.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_combinations_strings.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_if_is_substr.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_if_unique_char.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_largest_sum.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_non_repeating_number.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/find_sum_ints.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/finding_gcd.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/finding_if_prime.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/generate_prime.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/get_float_rep_bin.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/interserction_two_arrays.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/max_subarray_stocks.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/number_of_zeros_factorial.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/prod_other_ints.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/ransom_note.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/rev_string.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/reverse_words.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/math_arrays_and_strings/reverse_words_sentence.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/sorting_and_searching/deck_shuffling.txt (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/sorting_and_searching/quick_sort.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/trees_paths/binary_search_tree.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/trees_paths/binary_tree.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/trees_paths/check_whether_bst.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/trees_paths/lowest_common_ancestor.py (100%) rename src/extra_interview_problems/{ => glassdoor/2014}/trees_paths/transversal_BST_ancestor.py (100%) create mode 100644 src/extra_interview_problems/glassdoor/2015/alpha_permutation.py create mode 100644 src/extra_interview_problems/glassdoor/2015/anagram.py delete mode 100644 src/extra_interview_problems/glassdoor/2015/anagram_sorting.py delete mode 100644 src/extra_interview_problems/glassdoor/2015/bucket.py rename src/extra_interview_problems/glassdoor/2015/{array_3_numbers.py => check_if_3_numbers_sum_to_zero.py} (100%) rename src/extra_interview_problems/glassdoor/2015/{tree.py => check_if_bst.py} (100%) rename src/extra_interview_problems/glassdoor/2015/{palindrome.py => check_if_palindrome.py} (87%) rename src/extra_interview_problems/glassdoor/2015/{overlapping.py => check_non_overlapping_intervals.py} (100%) delete mode 100644 src/extra_interview_problems/glassdoor/2015/comb.py rename src/extra_interview_problems/glassdoor/2015/{pairs.py => find_if_numbers_sum_to_k.py} (100%) create mode 100644 src/extra_interview_problems/glassdoor/2015/find_longest_str_unique_chars.py rename src/extra_interview_problems/glassdoor/2015/{fib.py => find_nth_fibonacci.py} (51%) create mode 100644 src/extra_interview_problems/glassdoor/2015/find_prime_factors.py delete mode 100644 src/extra_interview_problems/glassdoor/2015/long_string.py create mode 100644 src/extra_interview_problems/glassdoor/2015/longest_common_prefix.py delete mode 100644 src/extra_interview_problems/glassdoor/2015/longest_str.py rename src/extra_interview_problems/glassdoor/2015/{merge.py => merge_and_sort_two_arrays.py} (100%) delete mode 100644 src/extra_interview_problems/glassdoor/2015/primes.py delete mode 100644 src/extra_interview_problems/glassdoor/2015/rec_bt.py delete mode 100644 src/extra_interview_problems/glassdoor/2015/smallest_bst.py rename src/extra_interview_problems/glassdoor/2015/{sum_str.py => sum_two_numbers_as_strings.py} (100%) create mode 100644 src/extra_interview_problems/glassdoor/2015/transversing_bt.py diff --git a/src/extra_interview_problems/abstract_strucutres/HashTable.py b/src/extra_interview_problems/glassdoor/2014/abstract_strucutres/HashTable.py similarity index 100% rename from src/extra_interview_problems/abstract_strucutres/HashTable.py rename to src/extra_interview_problems/glassdoor/2014/abstract_strucutres/HashTable.py diff --git a/src/extra_interview_problems/abstract_strucutres/queue_with_stack.py b/src/extra_interview_problems/glassdoor/2014/abstract_strucutres/queue_with_stack.py similarity index 100% rename from src/extra_interview_problems/abstract_strucutres/queue_with_stack.py rename to src/extra_interview_problems/glassdoor/2014/abstract_strucutres/queue_with_stack.py diff --git a/src/extra_interview_problems/abstract_strucutres/stack_with_minumum.txt b/src/extra_interview_problems/glassdoor/2014/abstract_strucutres/stack_with_minumum.txt similarity index 100% rename from src/extra_interview_problems/abstract_strucutres/stack_with_minumum.txt rename to src/extra_interview_problems/glassdoor/2014/abstract_strucutres/stack_with_minumum.txt diff --git a/src/extra_interview_problems/advanced/lru_cache.py b/src/extra_interview_problems/glassdoor/2014/advanced/lru_cache.py similarity index 100% rename from src/extra_interview_problems/advanced/lru_cache.py rename to src/extra_interview_problems/glassdoor/2014/advanced/lru_cache.py diff --git a/src/extra_interview_problems/basic_examples/example_args.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_args.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_args.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_args.py diff --git a/src/extra_interview_problems/basic_examples/example_benchmark_decorator.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_benchmark_decorator.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_benchmark_decorator.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_benchmark_decorator.py diff --git a/src/extra_interview_problems/basic_examples/example_comp_lists.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_comp_lists.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_comp_lists.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_comp_lists.py diff --git a/src/extra_interview_problems/basic_examples/example_generator.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_generator.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_generator.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_generator.py diff --git a/src/extra_interview_problems/basic_examples/example_lambda.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_lambda.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_lambda.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_lambda.py diff --git a/src/extra_interview_problems/basic_examples/example_logging.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_logging.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_logging.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_logging.py diff --git a/src/extra_interview_problems/basic_examples/example_queue.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_queue.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_queue.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_queue.py diff --git a/src/extra_interview_problems/basic_examples/example_socket.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_socket.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_socket.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_socket.py diff --git a/src/extra_interview_problems/basic_examples/example_string_format.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_string_format.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_string_format.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_string_format.py diff --git a/src/extra_interview_problems/basic_examples/example_telnet.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_telnet.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_telnet.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_telnet.py diff --git a/src/extra_interview_problems/basic_examples/example_testing.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_testing.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_testing.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_testing.py diff --git a/src/extra_interview_problems/basic_examples/example_threads.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/example_threads.py similarity index 100% rename from src/extra_interview_problems/basic_examples/example_threads.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/example_threads.py diff --git a/src/extra_interview_problems/basic_examples/export_pickle.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/export_pickle.py similarity index 100% rename from src/extra_interview_problems/basic_examples/export_pickle.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/export_pickle.py diff --git a/src/extra_interview_problems/basic_examples/import_pickle.py b/src/extra_interview_problems/glassdoor/2014/basic_examples/import_pickle.py similarity index 100% rename from src/extra_interview_problems/basic_examples/import_pickle.py rename to src/extra_interview_problems/glassdoor/2014/basic_examples/import_pickle.py diff --git a/src/extra_interview_problems/bitwise/bitwise.txt b/src/extra_interview_problems/glassdoor/2014/bitwise/bitwise.txt similarity index 100% rename from src/extra_interview_problems/bitwise/bitwise.txt rename to src/extra_interview_problems/glassdoor/2014/bitwise/bitwise.txt diff --git a/src/extra_interview_problems/bitwise/clear_bits.py b/src/extra_interview_problems/glassdoor/2014/bitwise/clear_bits.py similarity index 100% rename from src/extra_interview_problems/bitwise/clear_bits.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/clear_bits.py diff --git a/src/extra_interview_problems/bitwise/find_bit_len.py b/src/extra_interview_problems/glassdoor/2014/bitwise/find_bit_len.py similarity index 100% rename from src/extra_interview_problems/bitwise/find_bit_len.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/find_bit_len.py diff --git a/src/extra_interview_problems/bitwise/get_bit.py b/src/extra_interview_problems/glassdoor/2014/bitwise/get_bit.py similarity index 100% rename from src/extra_interview_problems/bitwise/get_bit.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/get_bit.py diff --git a/src/extra_interview_problems/bitwise/num_bits_to_convert_2_nums.py b/src/extra_interview_problems/glassdoor/2014/bitwise/num_bits_to_convert_2_nums.py similarity index 100% rename from src/extra_interview_problems/bitwise/num_bits_to_convert_2_nums.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/num_bits_to_convert_2_nums.py diff --git a/src/extra_interview_problems/bitwise/set_bit.py b/src/extra_interview_problems/glassdoor/2014/bitwise/set_bit.py similarity index 100% rename from src/extra_interview_problems/bitwise/set_bit.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/set_bit.py diff --git a/src/extra_interview_problems/bitwise/swap_in_place.py b/src/extra_interview_problems/glassdoor/2014/bitwise/swap_in_place.py similarity index 100% rename from src/extra_interview_problems/bitwise/swap_in_place.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/swap_in_place.py diff --git a/src/extra_interview_problems/bitwise/update_bit.py b/src/extra_interview_problems/glassdoor/2014/bitwise/update_bit.py similarity index 100% rename from src/extra_interview_problems/bitwise/update_bit.py rename to src/extra_interview_problems/glassdoor/2014/bitwise/update_bit.py diff --git a/src/extra_interview_problems/design/design_pattern.txt b/src/extra_interview_problems/glassdoor/2014/design/design_pattern.txt similarity index 100% rename from src/extra_interview_problems/design/design_pattern.txt rename to src/extra_interview_problems/glassdoor/2014/design/design_pattern.txt diff --git a/src/extra_interview_problems/design/design_text_editor.txt b/src/extra_interview_problems/glassdoor/2014/design/design_text_editor.txt similarity index 100% rename from src/extra_interview_problems/design/design_text_editor.txt rename to src/extra_interview_problems/glassdoor/2014/design/design_text_editor.txt diff --git a/src/extra_interview_problems/design/example_decorator.py b/src/extra_interview_problems/glassdoor/2014/design/example_decorator.py similarity index 100% rename from src/extra_interview_problems/design/example_decorator.py rename to src/extra_interview_problems/glassdoor/2014/design/example_decorator.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/anagrams_hash_table.txt b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/anagrams_hash_table.txt similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/anagrams_hash_table.txt rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/anagrams_hash_table.txt diff --git a/src/extra_interview_problems/math_arrays_and_strings/balance.txt b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/balance.txt similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/balance.txt rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/balance.txt diff --git a/src/extra_interview_problems/math_arrays_and_strings/check_2_numbers_array_sum.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/check_2_numbers_array_sum.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/check_2_numbers_array_sum.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/check_2_numbers_array_sum.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/check_if_anagrams.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/check_if_anagrams.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/check_if_anagrams.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/check_if_anagrams.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/check_palindrome.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/check_palindrome.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/check_palindrome.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/check_palindrome.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/decide_if_permutation.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/decide_if_permutation.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/decide_if_permutation.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/decide_if_permutation.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/delete_duplicate_char_str.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/delete_duplicate_char_str.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/delete_duplicate_char_str.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/delete_duplicate_char_str.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/fibonacci.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/fibonacci.py similarity index 82% rename from src/extra_interview_problems/math_arrays_and_strings/fibonacci.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/fibonacci.py index 28ca28b..b6362bf 100755 --- a/src/extra_interview_problems/math_arrays_and_strings/fibonacci.py +++ b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/fibonacci.py @@ -1,8 +1,7 @@ #!/usr/bin/env python -__author__ = "Mari Wahl" -__email__ = "marina.w4hl@gmail.com" +__author__ = "bt3" ''' understanding generators''' diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_all_permutations_string.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_all_permutations_string.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_all_permutations_string.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_all_permutations_string.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_combinations_strings.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_combinations_strings.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_combinations_strings.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_combinations_strings.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_if_is_substr.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_if_is_substr.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_if_is_substr.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_if_is_substr.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_if_unique_char.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_if_unique_char.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_if_unique_char.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_if_unique_char.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_largest_sum.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_largest_sum.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_largest_sum.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_largest_sum.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_non_repeating_number.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_non_repeating_number.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_non_repeating_number.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_non_repeating_number.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/find_sum_ints.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_sum_ints.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/find_sum_ints.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/find_sum_ints.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/finding_gcd.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/finding_gcd.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/finding_gcd.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/finding_gcd.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/finding_if_prime.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/finding_if_prime.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/finding_if_prime.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/finding_if_prime.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/generate_prime.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/generate_prime.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/generate_prime.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/generate_prime.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/get_float_rep_bin.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/get_float_rep_bin.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/get_float_rep_bin.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/get_float_rep_bin.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/interserction_two_arrays.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/interserction_two_arrays.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/interserction_two_arrays.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/interserction_two_arrays.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/max_subarray_stocks.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/max_subarray_stocks.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/max_subarray_stocks.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/max_subarray_stocks.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/number_of_zeros_factorial.txt b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/number_of_zeros_factorial.txt similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/number_of_zeros_factorial.txt rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/number_of_zeros_factorial.txt diff --git a/src/extra_interview_problems/math_arrays_and_strings/prod_other_ints.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/prod_other_ints.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/prod_other_ints.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/prod_other_ints.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/ransom_note.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/ransom_note.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/ransom_note.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/ransom_note.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/rev_string.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/rev_string.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/rev_string.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/rev_string.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/reverse_words.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/reverse_words.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/reverse_words.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/reverse_words.py diff --git a/src/extra_interview_problems/math_arrays_and_strings/reverse_words_sentence.py b/src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/reverse_words_sentence.py similarity index 100% rename from src/extra_interview_problems/math_arrays_and_strings/reverse_words_sentence.py rename to src/extra_interview_problems/glassdoor/2014/math_arrays_and_strings/reverse_words_sentence.py diff --git a/src/extra_interview_problems/sorting_and_searching/deck_shuffling.txt b/src/extra_interview_problems/glassdoor/2014/sorting_and_searching/deck_shuffling.txt similarity index 100% rename from src/extra_interview_problems/sorting_and_searching/deck_shuffling.txt rename to src/extra_interview_problems/glassdoor/2014/sorting_and_searching/deck_shuffling.txt diff --git a/src/extra_interview_problems/sorting_and_searching/quick_sort.py b/src/extra_interview_problems/glassdoor/2014/sorting_and_searching/quick_sort.py similarity index 100% rename from src/extra_interview_problems/sorting_and_searching/quick_sort.py rename to src/extra_interview_problems/glassdoor/2014/sorting_and_searching/quick_sort.py diff --git a/src/extra_interview_problems/trees_paths/binary_search_tree.py b/src/extra_interview_problems/glassdoor/2014/trees_paths/binary_search_tree.py similarity index 100% rename from src/extra_interview_problems/trees_paths/binary_search_tree.py rename to src/extra_interview_problems/glassdoor/2014/trees_paths/binary_search_tree.py diff --git a/src/extra_interview_problems/trees_paths/binary_tree.py b/src/extra_interview_problems/glassdoor/2014/trees_paths/binary_tree.py similarity index 100% rename from src/extra_interview_problems/trees_paths/binary_tree.py rename to src/extra_interview_problems/glassdoor/2014/trees_paths/binary_tree.py diff --git a/src/extra_interview_problems/trees_paths/check_whether_bst.py b/src/extra_interview_problems/glassdoor/2014/trees_paths/check_whether_bst.py similarity index 100% rename from src/extra_interview_problems/trees_paths/check_whether_bst.py rename to src/extra_interview_problems/glassdoor/2014/trees_paths/check_whether_bst.py diff --git a/src/extra_interview_problems/trees_paths/lowest_common_ancestor.py b/src/extra_interview_problems/glassdoor/2014/trees_paths/lowest_common_ancestor.py similarity index 100% rename from src/extra_interview_problems/trees_paths/lowest_common_ancestor.py rename to src/extra_interview_problems/glassdoor/2014/trees_paths/lowest_common_ancestor.py diff --git a/src/extra_interview_problems/trees_paths/transversal_BST_ancestor.py b/src/extra_interview_problems/glassdoor/2014/trees_paths/transversal_BST_ancestor.py similarity index 100% rename from src/extra_interview_problems/trees_paths/transversal_BST_ancestor.py rename to src/extra_interview_problems/glassdoor/2014/trees_paths/transversal_BST_ancestor.py diff --git a/src/extra_interview_problems/glassdoor/2015/alpha_permutation.py b/src/extra_interview_problems/glassdoor/2015/alpha_permutation.py new file mode 100644 index 0000000..a67a534 --- /dev/null +++ b/src/extra_interview_problems/glassdoor/2015/alpha_permutation.py @@ -0,0 +1,34 @@ +#!/bin/python + +''' Write code to generate all possible case permutations of a given +lower-cased string +''' + +def alpha_permutation(string): + ''' + >>> alpha_permutation('0ab') + ['0Ab', '0Ab', '0ab', '0ab', '0Ba', '0Ba', '0ba', '0ba', 'ab0', 'a0b', 'a0b', 'b0a', 'b0a', 'ba0'] + >>> alpha_permutation('') + '' + ''' + + if len(string) < 2: + return string + + result = [] + + for i, c in enumerate(string): + rest = string[i+1:] + string[:i] + for cc in alpha_permutation(rest): + if cc.isalpha(): + result.append(c.upper() + cc) + result.append(c + cc) + + return result + + + +if __name__ == '__main__': + import doctest + doctest.testmod() + diff --git a/src/extra_interview_problems/glassdoor/2015/anagram.py b/src/extra_interview_problems/glassdoor/2015/anagram.py new file mode 100644 index 0000000..5f49364 --- /dev/null +++ b/src/extra_interview_problems/glassdoor/2015/anagram.py @@ -0,0 +1,31 @@ +#!/bin/python + +from collections import Counter + +def is_anagram(s1, s2): + ''' + >>> is_anagram('cat', 'tac') + True + >>> is_anagram('cat', 'hat') + False + ''' + counter = Counter() + for c in s1: + counter[c] += 1 + + for c in s2: + counter[c] -= 1 + + for i in counter.values(): + if i: + return False + + return True + + + + +if __name__ == '__main__': + import doctest + doctest.testmod() + diff --git a/src/extra_interview_problems/glassdoor/2015/anagram_sorting.py b/src/extra_interview_problems/glassdoor/2015/anagram_sorting.py deleted file mode 100644 index 3beefd7..0000000 --- a/src/extra_interview_problems/glassdoor/2015/anagram_sorting.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/python - -''' - anagram sorting. huge list that does not fit in memory? -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/bucket.py b/src/extra_interview_problems/glassdoor/2015/bucket.py deleted file mode 100644 index aab792e..0000000 --- a/src/extra_interview_problems/glassdoor/2015/bucket.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/python - -''' -Given a telephone directory which is broken in number of -files, how would you find a telephone number in it (bucket sort) - -- Quick Sort is a good choice when you have to sort a lot of elements. - When you are working with smaller collections, Bucket Sort may be a - better choice. -''' - - - - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/array_3_numbers.py b/src/extra_interview_problems/glassdoor/2015/check_if_3_numbers_sum_to_zero.py similarity index 100% rename from src/extra_interview_problems/glassdoor/2015/array_3_numbers.py rename to src/extra_interview_problems/glassdoor/2015/check_if_3_numbers_sum_to_zero.py diff --git a/src/extra_interview_problems/glassdoor/2015/tree.py b/src/extra_interview_problems/glassdoor/2015/check_if_bst.py similarity index 100% rename from src/extra_interview_problems/glassdoor/2015/tree.py rename to src/extra_interview_problems/glassdoor/2015/check_if_bst.py diff --git a/src/extra_interview_problems/glassdoor/2015/palindrome.py b/src/extra_interview_problems/glassdoor/2015/check_if_palindrome.py similarity index 87% rename from src/extra_interview_problems/glassdoor/2015/palindrome.py rename to src/extra_interview_problems/glassdoor/2015/check_if_palindrome.py index ab3f5dc..85d9c44 100644 --- a/src/extra_interview_problems/glassdoor/2015/palindrome.py +++ b/src/extra_interview_problems/glassdoor/2015/check_if_palindrome.py @@ -1,6 +1,5 @@ #!/bin/python -''' Determine if an Array of integers contains 3 numbers that sum to 0 ''' from collections import defaultdict diff --git a/src/extra_interview_problems/glassdoor/2015/overlapping.py b/src/extra_interview_problems/glassdoor/2015/check_non_overlapping_intervals.py similarity index 100% rename from src/extra_interview_problems/glassdoor/2015/overlapping.py rename to src/extra_interview_problems/glassdoor/2015/check_non_overlapping_intervals.py diff --git a/src/extra_interview_problems/glassdoor/2015/comb.py b/src/extra_interview_problems/glassdoor/2015/comb.py deleted file mode 100644 index a43cd5b..0000000 --- a/src/extra_interview_problems/glassdoor/2015/comb.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/python - -''' Write code to generate all possible case combinations of a given -lower-cased string. (e.g. "0ab" -> ["0ab", "0aB", "0Ab", "0AB"]) -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/pairs.py b/src/extra_interview_problems/glassdoor/2015/find_if_numbers_sum_to_k.py similarity index 100% rename from src/extra_interview_problems/glassdoor/2015/pairs.py rename to src/extra_interview_problems/glassdoor/2015/find_if_numbers_sum_to_k.py diff --git a/src/extra_interview_problems/glassdoor/2015/find_longest_str_unique_chars.py b/src/extra_interview_problems/glassdoor/2015/find_longest_str_unique_chars.py new file mode 100644 index 0000000..08a2a00 --- /dev/null +++ b/src/extra_interview_problems/glassdoor/2015/find_longest_str_unique_chars.py @@ -0,0 +1,35 @@ +#!/bin/python + +''' +given a string, find longest string with unique characters +''' + +def find_longest(string): + ''' + >>> find_longest('abfgrhgtrdsandwejfhdasjcbdsjvrejwghireeej') + 'wejfhdas' + >>> find_longest('abcabcabcabcdefabcccc') + 'defabc' + ''' + maxs = '' + result = '' + + for c in string: + if c in result: + if len(maxs) < len(result): + maxs = result + result = '' + else: + result += c + + if result and len(maxs) < len(result): + maxs = result + + return maxs + + + +if __name__ == '__main__': + import doctest + doctest.testmod() + diff --git a/src/extra_interview_problems/glassdoor/2015/fib.py b/src/extra_interview_problems/glassdoor/2015/find_nth_fibonacci.py similarity index 51% rename from src/extra_interview_problems/glassdoor/2015/fib.py rename to src/extra_interview_problems/glassdoor/2015/find_nth_fibonacci.py index 540e27d..8a63ef6 100644 --- a/src/extra_interview_problems/glassdoor/2015/fib.py +++ b/src/extra_interview_problems/glassdoor/2015/find_nth_fibonacci.py @@ -6,6 +6,28 @@ Optimize your code so that the numbers don't have to be recalculated on consecutive function call ''' +def fib(n): + ''' + >>> fib(2) + 1 + >>> fib(5) + 5 + >>> fib(7) + 13 + ''' + + if n < 3: + return 1 + + a, b = 0, 1 + count = 1 + + while count < n: + count += 1 + a, b = b, a+b + + return b + if __name__ == '__main__': import doctest diff --git a/src/extra_interview_problems/glassdoor/2015/find_prime_factors.py b/src/extra_interview_problems/glassdoor/2015/find_prime_factors.py new file mode 100644 index 0000000..59f22f2 --- /dev/null +++ b/src/extra_interview_problems/glassdoor/2015/find_prime_factors.py @@ -0,0 +1,34 @@ +#!/bin/python + +''' +find prime factors of a number. +''' + +import math + +def find_prime_factors(n): + ''' + >>> find_prime_factors(14) + [2, 7] + >>> find_prime_factors(19) + [] + ''' + + divisors = [d for d in range(2, n//2 + 1) if n % d == 0] + primes = [d for d in divisors if is_prime(d)] + + return primes + + +def is_prime(n): + for j in range(2, int(math.sqrt(n))): + if (n % j) == 0: + return False + return True + + + +if __name__ == '__main__': + import doctest + doctest.testmod() + diff --git a/src/extra_interview_problems/glassdoor/2015/long_string.py b/src/extra_interview_problems/glassdoor/2015/long_string.py deleted file mode 100644 index 717d802..0000000 --- a/src/extra_interview_problems/glassdoor/2015/long_string.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/python - -''' -Given a list of strings, write a function -to calculate the longest common prefix (LCP) of all those strings. -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/longest_common_prefix.py b/src/extra_interview_problems/glassdoor/2015/longest_common_prefix.py new file mode 100644 index 0000000..cbcec8d --- /dev/null +++ b/src/extra_interview_problems/glassdoor/2015/longest_common_prefix.py @@ -0,0 +1,38 @@ +#!/bin/python + +''' +Given two strings, write a function +to calculate the longest common prefix (LCP) of the strings. +''' + +def lcp(s1, s2): + ''' + >>> lcp('dabbd', 'aabbaa') + 3 + >>> lcp('abcd', 'hi') + 0 + ''' + + p1 = 0 + aux, lcp = '', '' + string1 = min(s1, s2) + string2 = max(s1, s2) + + while p1 < len(string1): + p2 = 0 + while p2 < len(string2) and p1+p2 < len(string1): + if string1[p1+p2] == string2[p2]: + aux += string1[p1+p2] + else: + if len(lcp) < len(aux): + lcp = aux + aux = '' + p2 += 1 + p1 += 1 + + return len(lcp) + +if __name__ == '__main__': + import doctest + doctest.testmod() + diff --git a/src/extra_interview_problems/glassdoor/2015/longest_str.py b/src/extra_interview_problems/glassdoor/2015/longest_str.py deleted file mode 100644 index d4e7f06..0000000 --- a/src/extra_interview_problems/glassdoor/2015/longest_str.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/python - -''' -given a string, find longest string with unique characters -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/merge.py b/src/extra_interview_problems/glassdoor/2015/merge_and_sort_two_arrays.py similarity index 100% rename from src/extra_interview_problems/glassdoor/2015/merge.py rename to src/extra_interview_problems/glassdoor/2015/merge_and_sort_two_arrays.py diff --git a/src/extra_interview_problems/glassdoor/2015/permutations.py b/src/extra_interview_problems/glassdoor/2015/permutations.py index 0714630..c753457 100644 --- a/src/extra_interview_problems/glassdoor/2015/permutations.py +++ b/src/extra_interview_problems/glassdoor/2015/permutations.py @@ -2,15 +2,22 @@ ''' Generate all permutations of an alphanumeric string ''' - def get_permutations(word): - if len(word) < 2: - yield word - return +def permutations(word): + ''' + >>> permutations('abc') + ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'] + >>> permutations('') + '' + ''' + if len(word) < 2: + return word - for i in range(len(word)): - rest = word[:i] + word[i+1:] - for tail in get_permutations(rest): - yield word[i] + tail + res = [] + for i in range(len(word)): + rest = word[:i] + word[i+1:] + for p in permutations(rest): + res.append(word[i] + p) + return res diff --git a/src/extra_interview_problems/glassdoor/2015/primes.py b/src/extra_interview_problems/glassdoor/2015/primes.py deleted file mode 100644 index 5ebafc1..0000000 --- a/src/extra_interview_problems/glassdoor/2015/primes.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/python - -''' -find prime factors of a number. -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/rec_bt.py b/src/extra_interview_problems/glassdoor/2015/rec_bt.py deleted file mode 100644 index 798c137..0000000 --- a/src/extra_interview_problems/glassdoor/2015/rec_bt.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/python - -''' -Reconstruct a binary tree given two sequences of node traversals, -one from inorder and one from postorder traversal. -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/smallest_bst.py b/src/extra_interview_problems/glassdoor/2015/smallest_bst.py deleted file mode 100644 index 9d1cf71..0000000 --- a/src/extra_interview_problems/glassdoor/2015/smallest_bst.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/python - -''' -find the smallest number in a BST -''' - - -if __name__ == '__main__': - import doctest - doctest.testmod() - diff --git a/src/extra_interview_problems/glassdoor/2015/sum_str.py b/src/extra_interview_problems/glassdoor/2015/sum_two_numbers_as_strings.py similarity index 100% rename from src/extra_interview_problems/glassdoor/2015/sum_str.py rename to src/extra_interview_problems/glassdoor/2015/sum_two_numbers_as_strings.py diff --git a/src/extra_interview_problems/glassdoor/2015/transversing_bt.py b/src/extra_interview_problems/glassdoor/2015/transversing_bt.py new file mode 100644 index 0000000..ba1b915 --- /dev/null +++ b/src/extra_interview_problems/glassdoor/2015/transversing_bt.py @@ -0,0 +1,50 @@ +#!/bin/python + +''' +Reconstruct a binary tree given two sequences of node traversals, +one from inorder and one from postorder traversal. +''' + +class Node(object): + def __init__(self, value, right=None, left=None): + self.value = value + self.right = right + self.left = left + +def create_tree(): + tree = Node(4) + tree.right = Node(6) + tree.left = Node(2) + tree.right.left = Node(5) + tree.right.right = Node(7) + tree.left.left = Node(1) + tree.left.right = Node(3) + return tree + +def inorder(tree): + if tree: + if tree.left: + inorder(tree.left) + print tree.value + if tree.right: + inorder(tree.right) + +def postorder(tree): + if tree: + if tree.left: + postorder(tree.left) + if tree.right: + postorder(tree.right) + print tree.value + + + + + +if __name__ == '__main__': + tree = create_tree() + print 'Printing inorder...' + inorder(tree) + print + print 'Printing postorder...' + postorder(tree) diff --git a/src/extra_interview_problems/glassdoor/2015/trie.py b/src/extra_interview_problems/glassdoor/2015/trie.py index c8a93c3..72fa541 100644 --- a/src/extra_interview_problems/glassdoor/2015/trie.py +++ b/src/extra_interview_problems/glassdoor/2015/trie.py @@ -2,11 +2,61 @@ ''' Implement a trie. (Write the API and code for inserting into a trie). - ''' +def make_trie(*args): + trie = {} + + for word in args: + temp_trie = trie + for letter in word: + temp_trie = temp_trie.setdefault(letter, {}) + temp_trie = temp_trie.setdefault('_end_', '_end_') + + return trie + + +def in_trie(trie, word): + temp_trie = trie + for letter in word: + if letter not in temp_trie: + return False + temp_trie = temp_trie[letter] + return True + + +def remove_from_trie(trie, word, depth): + if word and word[depth] not in trie: + return False + + if len(word) == depth + 1: + del trie[word[depth]] + if not trie: + return True + return False + else: + temp_trie = trie + + if remove_from_trie(temp_trie[word[depth]], word, depth + 1): + if temp_trie: + del temp_trie[word[depth]] + return not temp_trie + return False + if __name__ == '__main__': - import doctest - doctest.testmod() + trie = make_trie('hello', 'abc', 'baz', 'bar', 'barz') + print 'This is the trie:' + print trie + + assert(in_trie(trie, 'hello') == True) + assert(in_trie(trie, 'bar') == True) + assert(in_trie(trie, 'bab') == False) + assert(in_trie(trie, 'zzz') == False) + + remove_from_trie(trie, 'abc', 0) + assert(in_trie(trie, 'abc') == False) + + +