This repo contains my solutions to algorithmic problems in leetcode.com and algoexpert.io written in Swift and Python.
Here is my leetcode profile.
About • Topics • Tips • LeetCode.com • AlgoExpert.io • References
I have solved quite a number of problems from several topics. See the below table for further details.
- Python, Swift
- Binary Search
- Binary Search Tree
- Binary Tree(Segment Tree)
- N-aray Tree(Trie, Binary Indexed Tree)
- Graph(Dijkstra, Union Find, Kruskal, Prim's, Minimum Spanning Tree, Topological Ordering...etc)
- Stack
- Queue
- Array
- Sorting
- Hash Table
- Heap
- Linked list
- Bit Operation
- Dynamic programming
- Backtracking(Permutations & Combinations & Subsets...etc)
- Math
- and more...
- Leetcode
- Algoexpert.io
- Glassdoor
- Interviews
- ...
- Whenever you solve a new question with some new techniques/algorithms, try to solve atleast 2 similar problem in a row. This way, your understanding to the new techniques/algorithms will be better.
- ...
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 3. Longest Substring Without Repeating Characters | ||||
02 | 412. Fizz Buzz | Swift | |||
03 | 937. Reorder Log Files | Python | |||
03 | 929. Unique Email Addresses | Python | |||
04 | 7. Reverse Integer | Python | |||
05 | 13. Roman to Integer | Python | |||
06 | 125. Valid Palindrome | Python | |||
07 | 161. One Edit Distance | Python | |||
08 | 1119. Remove Vowels from a String | Python | |||
09 | 344. Reverse String | Python | |||
10 | 482. License Key Formatting | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 2. Add Two Numbers | Swift | |||
02 | 707. Design Linked List | Python | |||
03 | 21. Merge Two Sorted Lists | Python | |||
04 | 206. Reverse Linked List | Python | |||
05 | 24. Swap Nodes in Pairs | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 20. Valid Parentheses | Python | |||
02 | 155. Min Stack | Python | |||
03 | 84. Largest Rectangle in Histogram | Python | Video 01, Video 02, Article 01, Article 02 | Hard | 📌 Need to revise |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 253_Meeting_Rooms_II | Python | Official | Medium | --- |
02 | 347. Top K Frequent Elements | Python | Helper 1, Helper 2, heapq, Counter | Medium | --- |
03 | 767. Reorganize String | Python | --- | Medium | Also check Greedy approach |
04 | 621. Task Scheduler | Python | Ex 1, Ex 2, Vid 1, Vid 2, Vid 3, Vid 4 | Medium | 📌 Extremely tricky. Classic problem |
05 | 358. Rearrange String k Distance Apart | Python | --- | Hard | 📌 Similar to 621. Task Scheduler |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 704. Binary Search | Python | |||
03 | 240. Search a 2D Matrix II | Python | Video 01, Video 02 | ||
04 | 74. Search a 2D Matrix | Python | Video 01, Video 02 | ||
05 | 1011. Capacity To Ship Packages Within D Days | Python | Discussion 1, Discussion 2, Discussion 3 | Medium | Difficult to spot the pattern, revise again |
06 | 410. Split Array Largest Sum | Python | Article 01 | Hard | 📌 Not done |
07 | 4. Median of Two Sorted Arrays | Python | Article 01, Video 1 | Hard | 📌 Classic problem |
08 | 981. Time Based Key-Value Store | Python | Article 01 | Medium | 📌 |
09 | 222. Count Complete Tree Nodes | Python | Theory, Official Solution, Fantastic idea! | Medium | 📌 BS within BS |
10 | 1231. Divide Chocolate | Python | Art 1, Art 2, Art 3, Vid 1 | Hard | 📌 Not done. Check again. Solve all similar question |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 701. Insert into a Binary Search Tree | Python | |||
02 | 700. Search in a Binary Search Tree | Python | |||
03 | 270. Closest Binary Search Tree Value | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 589. N-ary Tree Preorder Traversal | Python | |||
02 | 590. N-ary Tree Postorder Traversal | Python | |||
03 | 429. N-ary Tree Level Order Traversal | Python | |||
06 | 559. Maximum Depth of N-ary Tree | Python | |||
07 | 431. Encode N-ary Tree to Binary Tree | Python | Explanation | ||
08 | 428. Serialize and Deserialize N-ary Tree | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 450. Delete Node in a BST | Python | |||
02 | 98. Validate Binary Search Tree | Python | |||
03 | 94. Binary Tree Inorder Traversal | Python | |||
04 | 144. Binary Tree Preorder Traversal | Python | |||
05 | 145. Binary Tree Postorder Traversal | Python | |||
06 | 226. Invert Binary Tree | Python | |||
07 | 101. Symmetric Tree | Python | |||
08 | 102. Binary Tree Level Order Traversal | Python | |||
09 | 107. Binary Tree Level Order Traversal II | Python | |||
10 | 103. Binary Tree Zigzag Level Order Traversal | Python | |||
11 | 695. Max Area of Island | Python | |||
12 | 104. Maximum Depth of Binary Tree | Python | Explanation | ||
13 | 100. Same Tree | Python | |||
14 | 11. Minimum Depth of Binary Tree | Python | Easy | --- | |
15 | 110. Balanced Binary Tree | Python | Video 1, Article 1, Article 2 | Easy | --- |
16 | 315. Count of Smaller Numbers After Self | Python | Article 1, Article 2, Vid 1, Vid 2 | Hard (Very) | 📌Very hard. First learn BIT, ST, AVL-Tree and Red-Black Tree then try again |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 208. Implement Trie (Prefix Tree) | Python | |||
02 | 211. Add and Search Word. Data structure design | Python | Video 01, Video 02 | ||
03 | 642. Design Search Autocomplete System | Python | Article 01, Video 01 | Hard | --- |
(BFS, DFS, Dijkstra, Union Find, Kruskal, Prim's, Minimum Spanning Tree, Topological Ordering...etc)
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 200. Number of Islands | Python | --- | Medium | DFS, Union Find |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 509. Fibonacci Number | Python | |||
02 | 50. Pow(x, n) | Python | |||
00 | It's a general topics which has been covered on Backtracking and graph problems | --- | --- | --- | --- |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 1055. Shortest Way to Form String | Python | Art 1, Art 2 | Medium | 📌 Check BS approach again |
02 | 1057. Campus Bikes | Python | Video 01, Article 01 | Medium | 📌 Solve 1066. Campus Bikes II using DP, DFS and Priority Queue |
03 | 1007. Minimum Domino Rotations For Equal Row | Python | Official, Article 01 | Medium | 📌 Hard to spot if it is a Greedy |
04 | 406. Queue Reconstruction by Height | Python | Article 1, Article 2 | Medium | 📌 Fundamentals |
05 | 621. Task Scheduler | Python | Ex 1, Ex 2, Vid 1, Vid 2, Vid 3, Vid 4 | Medium | 📌 Extremely tricky. Classic problem |
06 | 392. Is Subsequence | Python | Ex 1, Ex 3 | Easy | 📌 |
07 | 55. Jump Game | Python | Official , Art 1 | Medium | 📌 Must Check. Learned a lot |
08 | 45. Jump Game II | Python | Vid 1, Vid 2, Vid 3, Art 1 | Hard | 📌 |
09 | 767. Reorganize String | Python | --- | Medium | Also check Heap approach |
10 | 435. Non-overlapping Intervals | Python | Vid 1, Art 1 | Medium | Classic problem |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 78. Subsets | Python | Video 1, Video 2, Video 3 | Medium | 📌 TODO: code it in all 4 ways. First complete DFS, BFS, Bit Manipulation and some easy back tracking problem. ⭐ 😭 Didn't understand, check again |
02 | 136. Single Number | Python | --- | Easy | 📌 The key here is to practice bit operation, i ignore any other attempts |
03 | 461. Hamming Distance | Python | --- | Easy | 📌 The key here is to practice bit operation, i ignore any other attempts |
04 | 371. Sum of Two Integers | Python | Video 1, Atricle 1 | Easy | 📌 The key here is to practice bit operation, i ignore any other attempts |
05 | 169. Majority Element | Python | Atricle 1 | Easy | 📌 The key here is to practice bit operation, i ignore any other attempts |
06 | 191. Number of 1 Bits | Python | Article 1 | Easy | 📌 The key here is to practice bit operation |
07 | 137. Single Number II | Python | 1, 2, 3, Check discussion | Medium | ⭐ 😭 Didn't understand, check again |
08 | 389. Find the Difference | Python | --- | Easy | 📌 |
09 | 231. Power of Two | Python | Official, Signed number representations | Easy | 📌 Learned few very important binary logic properties |
10 | 268. Missing Number | Python | Official | Easy | 📌 Learned few very important binary logic properties |
11 | 187. Repeated DNA Sequences | Python | Official | Medium | ⭐ 😭 Didn't understand, check again |
77 Problems
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Two_Number_Sum | Swift, Python | |||
02 | Three_Number_Sum | Python | |||
03 | Smallest_Difference | Python | |||
04 | Four_Number_Sum | Python | |||
05 | Subarray_Sort | Python | |||
06 | Largest_Range | Python | |||
07 | Min_Rewards | Python | |||
08 | Zigzag_Traverse | Python | |||
08 | Apartment_Hunting | Python | |||
09 | Calendar_Matching | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | BST_Construction_Iterative | Python | |||
02 | BST_Construction_Recursive | Python | |||
03 | Validate_BST | Python | |||
04 | Find_Closest_Value_in_BST | Python | |||
05 | BST_Traversal | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Invert_Binary_Tree | Python | |||
02 | Max_Path_Sum_In_Binary_Tree | Python | |||
03 | Iterative_In-order_Traversal | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Number_Of_Ways_To_Make_Changes | Python | |||
02 | Minimum_Number_Of_Coins_For_Change | Python | |||
03 | Levenshtein_Distance | Python | |||
04 | Min_Number_Of_Jumps | Python | Video 1 | ||
05 | Max_Sum_Increasing_Subsequence | Python | |||
06 | Longest_Common_Subsequence | Python | Video 1 | ||
07 | Water_Area | Python | |||
08 | Knapsack_Problem | Python | |||
09 | Disk_Stacking | Python | |||
10 | Numbers_In_Pi | Python | |||
11 | Maximum_Subset_Sum_With_No_Adjacent_Element | Python | |||
12 | Max_Profit_With_K_Transactions | Python | |||
13 | Palindrome_Partitioning_Min_Cuts | Python | |||
14 | Longest_Increasing_Subsequence | Python | Video 1, Video 2, , Video 3 |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Kadane's_Algorithm | Python | |||
02 | Topological_Sort | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Youngest_Common_Ancestor | Python | |||
02 | Single_Cycle_Check | Python | |||
03 | River_Sizes | Python | |||
04 | Depth_First_Search | Python | |||
05 | Breadth_First_Search | Python | |||
06 | Boggle_Board | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Min_Heap_Construction | Python | Video 1 | ||
02 | Continuous_Median | Python | Video 1, Video 2 |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Remove_Kth_Node_From_End | Python | |||
02 | Linked_List_Construction | Python | |||
03 | Find_Loop | Python | |||
04 | Reverse_Linked_List | Python | |||
05 | LRU_Cache | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Powerset | Python | |||
02 | Permutations | Python | |||
03 | Nth_Fibonacci | Python | |||
04 | Product_Sum | Python | |||
05 | Lowest_Common_Manager | Python | |||
06 | Number_Of_Possible_Binary_Tree_Topologies | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Search_In_Sorted_Matrix | Python | |||
02 | Find_Three_Largest_Number | Python | |||
03 | Binary_Search | Python | |||
04 | Shifted_Binary_Search | Python | |||
05 | Search_For_Range | Python | |||
06 | Quick_Select (Kth smallest/largest element) | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Selection_Sort | Python | |||
02 | Insertion_Sort | Python | |||
03 | Bubble_Sort | Python | |||
04 | Quick_Sort | Python | Video 1 | ||
05 | Heap_Sort | Python | |||
06 | Merge_Sort | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Balanced Bracket | Python | |||
02 | Min_Max_Stack_Construction | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Palindrom_Check | Python | |||
02 | Longest_Palindromic_Substring | Python | |||
03 | Caesar_Cipher_Encryptor | Python | |||
04 | Longest_Substring_Without_Duplication | Python | |||
05 | Underscorify_Substring | Python | |||
06 | Pattern_Matcher | Python |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Suffix_Trie_Construction | Python | |||
02 | Multi_String_Search | Python |
Some helpful links, channels, tutorials, blogs.
Strategies
- How a Googler solves coding problems
- Nail Every Coding Interview by Becoming Asymmetrical
- How to get into FAANG
- Preparing for Programming interview with Python
- The 30-minute guide to rocking your next coding interview
- Google Interview Part-1 , Google Interview Part-2, Google Interview Part-3, Final Part
- Amazon ও Google এ চাকরির সুযোগ পাওয়ার প্রস্তুতি পর্ব
- How to use LeetCode effectively
- How to solve ANY interview question
- How To Ace The Google Coding Interview - Complete Guide
- Software Engineering Interviews: The Golden Path To Passing
- A MUST READ
Courses/Books
- Data Structures in Python: An Interview Refresher
- Grokking the Coding Interview: Patterns for Coding Questions
- Grokking Dynamic Programming Patterns for Coding Interviews
- Coding Interview Class
- Competitive Programmer’s Handbook
Python
Learn the following modules by heart. Just knowing all of the following items will made most of the problem one-liners.
- itertools - Functions creating iterators for efficient looping - They will help you, more often than you think
- collections - High-performance container datatypes - Believe me, this is pretty awesome
- heapq - Heap queue algorithm - Obviously, we don't have to hand-code heaps anymore
- bisect - Array bisection algorithm - Binary Search, simplified
- Set
- Dict - Now on, hash Tables are fun to work with
- Sorting - Don't participate in competitions without reading this completely.
- Start using lambda extensively
- functools
- Apart from these, all the builtin methods of default containers.
- Understanding slice notation - you will need/use it more than you can imagine
Channels
Tree (Tree, BST, BIT, Segment Tree, N-aray Tree, Trie etc)
- Fenwick Tree or Binary Indexed Tree - youtube
- Binary Indexed Tree or Fenwick Tree - geeksforgeeks
- Binary Indexed Tree or Fenwick Tree - topcoder
- Segment Tree Range Minimum Query - youtube
- Segment Tree | Set 1 (Sum of given range) - geeksforgeeks
- Practical Data Structures for Frontend Applications: When to use Segment Trees
- What is the difference between a binary indexed tree and a segment tree?
- How does one decide when to use a Segment Tree or Fenwick Tree?
- What are the differences between segment trees, interval trees, binary indexed trees and range trees?
Graph(Dijkstra, Union Find, Kruskal, Prim's, Minimum Spanning Tree, Topological Ordering...etc)
- Graph Theory Playlist
- Union Find [Disjoint Set] Playlist
- Disjoint Sets Data Structure - Weighted Union and Collapsing Find
Bit Manipulation
- Bit Manipulation - youtube
- Conversion of Binary, Octal and Hexadecimal Numbers
- Your guide to Bit Manipulation
- Python Bitwise Operators
- Add Two Numbers Without The "+" Sign (Bit Shifting Basics)
- Binary Arithmetic
- 1’s and 2’s complement of a Binary Number
- What is “2's Complement”?
- Bits manipulation (Important tactics)
- Bit Manipulation
- Python Bitwise Operators
- XOR - The magical bitwise operator
- A summary: how to use bit manipulation to solve problems easily and efficiently - leetcode
- Bit Manipulation 4% of LeetCode Problems
- Coding Interview University - Bitwise operations
- Mask (computing)
- What is Bit Masking?
- Understanding Bit masks
- Bitmasks: A very esoteric (and impractical) way of managing booleans
- Hacker’s Delight - BOOK
- Bitwise operators — Facts and Hacks
- Signed number representations
Dynamic Programming
Greedy
- Greedy Method - Introduction
- Introduction to Greedy Method
- Introduction to Greedy Algorithms | GeeksforGeeks
- Basics of Greedy Algorithms
- When to try greedy algorithms on problems?
- How to spot a “greedy” algorithm?
DP VS Greedy
- Greedy Algorithm and Dynamic Programming
- Greedy approach vs Dynamic programming
- What is the difference between dynamic programming and greedy approach?
Backtracking
- Backtracking - wiki
- Backtracking | Introduction
- Introduction to Backtracking - Brute Force Approach
- Branch and Bound Introduction
- The Backtracking Blueprint: The Legendary 3 Keys To Backtracking Algorithms
- Backtracking explained
- Foundation of algorithms - Chapter 5 (Backtracking) notes
- Backtracking Search Algorithms
Recursion
- Learning to think with recursion, part 1
- Learning to think with recursion, part 2
- What makes a data structure recursive?
- Binary Tree as a Recursive Data Structure
- Recursion Visualizer - use Viz Mode
- Thinking Recursively in Python
- Breaking out of a recursive function?
- Why does recursion return the first call in the stack and not the last?