GitHub - kimtth/algorithm-interview-prep-with-visual: 👨‍💻 Learn common interview algorithms with step-by-step visuals 🖼️ and animations 🎞️

Important

Translated version from the Korean version into English with D3.js visualization — master coding tests with 95 algorithm problems.

🚀 Quick Start

Open Visualization Index

👉 Open index.html to browse all problems with interactive visualizations.

★ Errata: https://www.onlybook.co.kr/entry/algorithm-interview-errata
★ Book Info: https://www.onlybook.co.kr/entry/algorithm-interview
★ YouTube: https://www.youtube.com/watch?v=fNyGHpSWhTA

Problem Solutions

# Title Difficulty Chapter Solution Code
1 Valid Palindrome Ch6. String Manipulation 1-1.py
1-2.py
1-3.py
1-4.c
2 Reverse String Ch6. String Manipulation 2-1.py
2-2.py
3 Reorder Data in Log Files Ch6. String Manipulation 3-1.py
4 Most Common Word Ch6. String Manipulation 4-1.py
5 Group Anagrams ★★ Ch6. String Manipulation 5-1.py
6 Longest Palindromic Substring ★★ Ch6. String Manipulation 6-1.py
7 Two Sum Ch7. Arrays 7-1.py
7-2.py
7-3.py
7-4.py
7-5.py
7-6.go
8 Trapping Rain Water ★★★ Ch7. Arrays 8-1.py
8-2.py
9 3Sum ★★ Ch7. Arrays 9-1.py
9-2.py
10 Array Partition I Ch7. Arrays 10-1.py
10-2.py
10-3.py
11 Product of Array Except Self ★★ Ch7. Arrays 11-1.py
12 Best Time to Buy and Sell Stock Ch7. Arrays 12-1.py
12-2.py
13 Palindrome Linked List Ch8. Linked Lists 13-1.py
13-2.py
13-3.go
13-4.py
14 Merge Two Sorted Lists Ch8. Linked Lists 14-1.py
15 Reverse Linked List Ch8. Linked Lists 15-1.py
15-2.py
16 Add Two Numbers ★★ Ch8. Linked Lists 16-1.py
16-2.py
17 Swap Nodes in Pairs ★★ Ch8. Linked Lists 17-1.py
17-2.py
17-3.py
18 Odd Even Linked List ★★ Ch8. Linked Lists 18-1.py
19 Reverse Linked List II ★★ Ch8. Linked Lists 19-1.py
20 Valid Parentheses Ch9. Stack, Queue 20-1.py
21 Remove Duplicate Letters ★★★ Ch9. Stack, Queue 21-1.py
21-2.py
22 Daily Temperatures ★★ Ch9. Stack, Queue 22-1.py
23 Implement Stack using Queues Ch9. Stack, Queue 23-1.py
24 Implement Queue using Stacks Ch9. Stack, Queue 24-1.py
25 Design Circular Queue ★★ Ch9. Stack, Queue 25-1.py
26 Design Circular Deque ★★ Ch10. Deque, Priority Queue 26-1.py
27 Merge k Sorted Lists Ch10. Deque, Priority Queue 27-1.py
28 Design HashMap Ch11. Hash Table 28-1.py
29 Jewels and Stones Ch11. Hash Table 29-1.py
29-2.py
29-3.py
29-4.py
30 Longest Substring Without Repeating Characters ★★ Ch11. Hash Table 30-1.py
31 Top K Frequent Elements ★★ Ch11. Hash Table 31-1.py
31-2.py
32 Number of Islands ★★ Ch12. Graph 32-1.py
33 Letter Combinations of a Phone Number ★★ Ch12. Graph 33-1.py
34 Permutations ★★ Ch12. Graph 34-1.py
34-2.py
35 Combinations ★★ Ch12. Graph 35-1.py
35-2.py
36 Combination Sum ★★ Ch12. Graph 36-1.py
37 Subsets ★★ Ch12. Graph 37-1.py
38 Reconstruct Itinerary ★★ Ch12. Graph 38-1.py
38-2.py
38-3.py
39 Course Schedule ★★ Ch12. Graph 39-1.py
39-2.py
40 Network Delay Time ★★ Ch13. Shortest Path 40-1.py
41 Cheapest Flights Within K Stops ★★ Ch13. Shortest Path 41-1.py
42 Maximum Depth of Binary Tree Ch14. Tree 42-1.py
43 Diameter of Binary Tree Ch14. Tree 43-1.py
44 Longest Univalue Path Ch14. Tree 44-1.py
45 Invert Binary Tree Ch14. Tree 45-1.py
45-2.py
45-3.py
45-4.py
46 Merge Two Binary Trees Ch14. Tree 46-1.py
47 Serialize and Deserialize Binary Tree ★★★ Ch14. Tree 47-1.py
48 Balanced Binary Tree Ch14. Tree 48-1.py
49 Minimum Height Trees ★★ Ch14. Tree 49-1.py
50 Convert Sorted Array to Binary Search Tree Ch14. Tree 50-1.py
51 Binary Search Tree to Greater Sum Tree ★★ Ch14. Tree 51-1.py
52 Range Sum of BST Ch14. Tree 52-1.py
52-2.py
52-3.py
52-4.py
53 Minimum Distance Between BST Nodes Ch14. Tree 53-1.py
53-2.py
54 Construct Binary Tree from Preorder and Inorder Traversal ★★ Ch14. Tree 54-1.py
55 Kth Largest Element in an Array ★★ Ch15. Heap 55-1.py
55-2.py
55-3.py
55-4.py
56 Implement Trie (Prefix Tree) ★★ Ch16. Trie 56-1.py
57 Palindrome Pairs ★★★ Ch16. Trie 57-1.py
57-2.py
58 Sort List ★★ Ch17. Sorting 58-1.py
58-3.py
59 Merge Intervals ★★ Ch17. Sorting 59-1.py
60 Insertion Sort List ★★ Ch17. Sorting 60-1.py
60-2.py
61 Largest Number ★★ Ch17. Sorting 61-1.py
62 Valid Anagram Ch17. Sorting 62-1.py
63 Sort Colors ★★ Ch17. Sorting 63-1.py
64 K Closest Points to Origin ★★ Ch17. Sorting 64-1.py
65 Binary Search Ch18. Binary Search 65-1.py
65-2.py
65-3.py
65-4.py
66 Search in Rotated Sorted Array ★★ Ch18. Binary Search 66-1.py
67 Intersection of Two Arrays Ch18. Binary Search 67-1.py
67-2.py
67-3.py
68 Two Sum II - Input Array Is Sorted Ch18. Binary Search 68-1.py
68-2.py
68-3.py
68-4.py
68-5.py
69 Search a 2D Matrix II ★★ Ch18. Binary Search 69-1.py
69-2.py
70 Single Number Ch19. Bit Manipulation 70-1.py
71 Hamming Distance Ch19. Bit Manipulation 71-1.py
72 Sum of Two Integers ★★★ Ch19. Bit Manipulation 72-1.py
72-2.py
73 UTF-8 Validation ★★ Ch19. Bit Manipulation 73-1.py
74 Number of 1 Bits Ch19. Bit Manipulation 74-1.py
74-2.py
75 Sliding Window Maximum ★★★ Ch20. Sliding Window 75-1.py
75-2.py
76 Minimum Window Substring ★★★ Ch20. Sliding Window 76-1.py
76-2.py
76-3.py
77 Longest Repeating Character Replacement ★★ Ch20. Sliding Window 77-1.py
78 Best Time to Buy and Sell Stock II Ch21. Greedy Algorithm 78-1.py
78-2.py
79 Queue Reconstruction by Height ★★ Ch21. Greedy Algorithm 79-1.py
80 Task Scheduler ★★ Ch21. Greedy Algorithm 80-1.py
81 Gas Station ★★ Ch21. Greedy Algorithm 81-1.py
81-2.py
82 Assign Cookies Ch21. Greedy Algorithm 82-1.py
82-2.py
83 Majority Element Ch22. Divide and Conquer 83-1.py
83-2.py
83-3.py
83-4.py
84 Different Ways to Add Parentheses ★★ Ch22. Divide and Conquer 84-1.py
85 Fibonacci Number Ch23. Dynamic Programming 85-1.py
85-2.py
85-3.py
85-4.py
86 Maximum Subarray Ch23. Dynamic Programming 86-1.py
86-2.py
87 Climbing Stairs Ch23. Dynamic Programming 87-1.py
87-2.py
88 House Robber Ch23. Dynamic Programming 88-1.py
88-2.py

Additional Code (miscellaneous)

LeetCode Updates and More Efficient Solutions

  • Problem 7: Test cases were removed, resulting in different execution times. #62
  • Problem 25: For a more efficient solution, see #105.
  • Problem 33: For a more efficient solution, see #91.
  • Problem 35: For a more efficient solution, see #111.
  • Problem 36: For a more efficient solution, see #112.
  • Problem 41: Due to test case changes, the solution now times out. #104
  • Problem 47: Due to evaluation function changes, comment out the TreeNode declaration before running. #97
  • Problem 75: Additional test cases were added, solution no longer passes. For new solution, see #67.