{"id":25019670,"url":"https://github.com/djeada/coding-interviews","last_synced_at":"2025-03-30T10:11:45.299Z","repository":{"id":114371582,"uuid":"234950711","full_name":"djeada/Coding-Interviews","owner":"djeada","description":"My alternative solutions to challenges from Harry He's book \"Coding Interviews.\"","archived":false,"fork":false,"pushed_at":"2023-11-03T19:17:22.000Z","size":928,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T11:51:52.441Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djeada.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-19T19:08:29.000Z","updated_at":"2022-04-24T23:33:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2548ff9-6347-412d-8077-445f4ebfa020","html_url":"https://github.com/djeada/Coding-Interviews","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djeada%2FCoding-Interviews","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djeada%2FCoding-Interviews/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djeada%2FCoding-Interviews/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djeada%2FCoding-Interviews/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djeada","download_url":"https://codeload.github.com/djeada/Coding-Interviews/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301997,"owners_count":20755514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-05T11:51:23.459Z","updated_at":"2025-03-30T10:11:45.252Z","avatar_url":"https://github.com/djeada.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coding Interviews\nThis repository presents updated and modernized solutions to programming challenges found in Harry He's \"Coding Interviews\" book, which is a well-regarded resource for candidates preparing for coding interviews. The book can be purchased on Amazon [here](https://www.amazon.de/Coding-Interviews-Questions-Solutions-Programming/dp/1430247614).\n\n![Capture](https://user-images.githubusercontent.com/37275728/186154277-b2ef19e7-1d07-4e4f-8bb6-ba6887e05519.PNG)\n\n## Motivation\n\nHere are some specific aspects I focused on while modernizing the solutions:\n\n1. **Error Handling:** Replaced error codes with exceptions to handle errors more gracefully.\n2. **Input/Output:** Used `iostream` instead of `stdlib.h` for standard input and output operations.\n3. **Testing:** Swapped console tests with assertions to validate the solutions.\n4. **Data Structures:** Preferred using vectors over bare arrays for flexibility.\n5. **Looping:** Used iterators instead of integer counters for traversing collections.\n6. **Class Implementation:** Implemented collections using classes to encapsulate data.\n7. **References:** Used references instead of pointers where possible for safety and readability.\n8. **Functional Programming:** Employed lambdas for implementing private functions.\n9. **Simplifying Data:** Used STL pairs instead of creating custom structs.\n10. **Type Deduction:** Utilized the `auto` keyword for cleaner code and type deduction.\n\n## Scope and Limitations\n\nWhile I've endeavored to improve the solutions, it is important to note that:\n\n- This repository does not provide solutions to every problem mentioned in the book.\n- Some solutions in this repository may not correspond to problems directly from the book but are inspired by similar challenges.\n\n## Arrays\n\n| #   | Title                | Solution                                                                                                     |\n| --- | -------------------- | ------------------------------------------------------------------------------------------------------------ |\n| 1   | Array rotation       | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/array_rotation.cpp)                |\n| 2   | Duplicates           | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/duplicates.cpp)                   |\n| 3   | Majority element     | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/majority_element.cpp)             |\n| 4   | Merge arrays         | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/merge_arrays.cpp)                |\n| 5   | Min number           | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/min_number.cpp)                  |\n| 6   | Permutations         | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/permutations.cpp)                |\n| 7   | Reorder numbers      | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/1_Arrays/reorder_numbers.cpp)             |\n\n## Strings\n\n| #   | Title                    | Solution                                                                                                     |\n| --- | ------------------------ | ------------------------------------------------------------------------------------------------------------ |\n| 1   | Add numeric string       | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/add_numeric_string.cpp)       |\n| 2   | Allocate string          | [C](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/allocate_str.c)                 |\n| 3   | Anagram                  | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/anagram.cpp)                   |\n| 4   | Combinations             | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/combinations.cpp)              |\n| 5   | Delete char              | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/delete_char.cpp)              |\n| 6   | Delete duplicate chars   | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/delete_duplicate_chars.cpp)    |\n| 7   | Edit distance            | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/edit_distance.cpp)            |\n| 8   | First char appearing once| [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/first_char_appearing_once.cpp)|\n| 9   | Numeric string           | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/numeric_string.cpp)           |\n| 10  | Palindrome number        | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/palindrome_number.cpp)        |\n| 11  | Permutations             | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/permutations.cpp)             |\n| 12  | Regex                    | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/regex.cpp)                    |\n| 13  | Replace blanks           | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/replace_blanks.cpp)           |\n| 14  | Reverse words in a sentence | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/reverse_words_in_sentence.cpp)|\n| 15  | String path              | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/2_Strings/string_path.cpp)              |\n\n\n## Stack and Queue\n\n| #   | Title             | Solution                                                                                              |\n| --- | ----------------- | ----------------------------------------------------------------------------------------------------- |\n| 1   | Min in stack      | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/3_Stack_Queue/min_in_stack.cpp)   |\n| 2   | Push pop order    | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/3_Stack_Queue/stack_push_pop_order.cpp) |\n| 3   | Stream median     | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/3_Stack_Queue/stream_median.cpp) |\n\n## Lists\n\n| #   | Title                  | Solution                                                                                                   |\n| --- | ---------------------- | ---------------------------------------------------------------------------------------------------------- |\n| 1   | Clone complex list     | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/clone_complex_list.cpp)         |\n| 2   | Delete duplicates      | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/delete_duplicates.cpp)           |\n| 3   | Delete node            | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/delete_node.cpp)                 |\n| 4   | Kth node               | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/kth_node.cpp)                    |\n| 5   | Loops                  | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/loops.cpp)                       |\n| 6   | Merge lists            | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/merge.cpp)                       |\n| 7   | Print reversely         | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/print_reversely.cpp)             |\n| 8   | Reverse list           | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/reverse_list.cpp)               |\n| 9   | Sort list              | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/4_Lists/sort.cpp)                        |\n\n## Matrices\n\n| #   | Title                  | Solution                                                                                              |\n| --- | ---------------------- | ----------------------------------------------------------------------------------------------------- |\n| 1   | Fibonacci              | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/5_Matrices/fibonacci.cpp)          |\n| 2   | Partially sorted matrix| [C++](https://github.com/djeada/CodingInterviews/blob/master/src/5_Matrices/partially_sorted_matrix.cpp) |\n| 3   | Sorted matrix          | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/5_Matrices/sorted_matrix.cpp)       |\n\n## Classes\n\n| #   | Title                | Solution                                                                                                     |\n| --- | -------------------- | ------------------------------------------------------------------------------------------------------------ |\n| 1   | Arrow and dot        | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/6_Classes/arrow_and_dot.cpp)                |\n| 2   | Assigment operator   | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/6_Classes/assigment_operator.cpp)           |\n| 3   | Objective C          | [C](https://github.com/djeada/CodingInterviews/blob/master/src/6_Classes/objective_c.c)                      |\n\n## Bit operations\n\n| #   | Title                   | Solution                                                                                                     |\n| --- | ----------------------- | ------------------------------------------------------------------------------------------------------------ |\n| 1   | Count ones              | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/7_Bit_Operations/count_ones.cpp)           |\n| 2   | Modify numbers          | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/7_Bit_Operations/modify_number.cpp)        |\n| 3   | Two missing numbers     | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/7_Bit_Operations/two_missing_numbers.cpp)  |\n| 4   | Uniquely occuring numbers| [C++](https://github.com/djeada/CodingInterviews/blob/master/src/7_Bit_Operations/uniquely_occuring_numbers.cpp)|\n\n## Trees\n\n| #   | Title                    | Solution                                                                                                     |\n| --- | ------------------------ | ------------------------------------------------------------------------------------------------------------ |\n| 1   | Balance                  | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/balance.cpp)                        |\n| 2   | Construct binary tree    | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/construct_binary_tree.cpp)          |\n| 3   | Convert to list          | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/convert_to_list.cpp)                |\n| 4   | Depth                    | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/depth.cpp)                          |\n| 5   | Largest subtrees         | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/largest_subtrees.cpp)               |\n| 6   | Lowest ancestor          | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/lowest_ancestor.cpp)               |\n| 7   | Nodes at k distance      | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/nodes_at_k_distance.cpp)           |\n| 8   | Path                     | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/path.cpp)                          |\n| 9   | Print levels             | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/print_levels.cpp)                  |\n| 10  | Print zigzag             | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/8_Trees/print_zigzag.cpp)                  |\n\n## Other\n\n| #   | Title                    | Solution                                                                                                        |\n| --- | ------------------------ | --------------------------------------------------------------------------------------------------------------- |\n| 1   | Coin change              | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/9_Dynamic_Programming/coin_change.cpp)          |\n| 2   | Eight queens             | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/9_Dynamic_Programming/eight_queens.cpp)         |\n| 3   | Greatest sum subarrays   | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/9_Dynamic_Programming/greatest_sum_subarrays.cpp) |\n| 4   | K least numbers          | [C++](https://github.com/djeada/CodingInterviews/blob/master/src/9_Dynamic_Programming/k_least_numbers.cpp)      |\n\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjeada%2Fcoding-interviews","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjeada%2Fcoding-interviews","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjeada%2Fcoding-interviews/lists"}