This repo contains around 300 Leetcode.com and 85 Algoexpert.io problems with solutions using Swift and Python
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.
- 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
- ...
- Coding Interview Patterns
- Coding Interview Gym
- iOS Interview Gym
- Behavioural Interview Gym
- System Design Interview Gym
- Object Oriented Design Interview Gym
- 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.
- Solve all leetcode cards
- ...
Leetcode problems with solutions and tutorials/videos
2. String
Leetcode problems with solutions and tutorials/videos
3. Linked List
Leetcode problems with solutions and tutorials/videos
4. Stack, Queue
Leetcode problems with solutions and tutorials/videos
# | 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 |
04 | 394. Decode String | Python | --- | Medium | 📌 Classic stack problem |
05 | 239. Sliding Window Maximum | Python | Video 1, Official, Art 1, Art 2, Art 3, Art 4 | Hard | 📌 Can be solved using Heap, Deque and DP |
5. Heaps
Leetcode problems with solutions and tutorials/videos
Leetcode problems with solutions and tutorials/videos
7. Binary Tree
Leetcode problems with solutions and tutorials/videos
Check this [golden](https://tinyurl.com/ujopecz) post.
Leetcode problems with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 701. Insert into a Binary Search Tree | Python | --- | Medium | Fundamentals |
02 | 700. Search in a Binary Search Tree | Python | --- | Easy | Fundamentals |
03 | 270. Closest Binary Search Tree Value | Python | --- | Easy | Fundamentals |
04 | 450. Delete Node in a BST | Python | --- | Medium | Fundamentals |
05 | 98. Validate Binary Search Tree | Python | --- | Medium | Fundamentals |
06 | 94. Binary Tree Inorder Traversal | Python | --- | Medium | Fundamentals |
07 | 144. Binary Tree Preorder Traversal | Python | --- | Medium | Fundamentals |
08 | 145. Binary Tree Postorder Traversal | Python | --- | Hard | Fundamentals |
09 | 108. Convert Sorted Array to Binary Search Tree | Python | --- | Easy | Fundamentals |
10 | 109. Convert Sorted List to Binary Search Tree | Python | --- | Medium | Classic problem. Very important |
9. N-Ary Tree
Leetcode problems with solutions and tutorials/videos
# | 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 | |||
04 | 559. Maximum Depth of N-ary Tree | Python | |||
05 | 431. Encode N-ary Tree to Binary Tree | Python | Explanation | ||
06 | 428. Serialize and Deserialize N-ary Tree | Python |
Leetcode problems with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 315. Count of Smaller Numbers After Self | Python | Article 1, Article 2, Vid 1, Vid 2 | Hard (Very) | 📌 Very hard and important. First learn BIT, ST, AVL-Tree and Red-Black Tree then try again |
11. Tries
Leetcode problems with solutions and tutorials/videos
# | 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, Floyd–Warshall, Bellman-Ford, Kruskal, Prim's, Minimum Spanning Tree, Topological Ordering, Union Find. Follow this golden rule to approach any graph problem.
Leetcode problems with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 207. Course Schedule | Python | educative.io | Medium | 📌 Very Important. Check again. BFS, Topological Sort |
02 | 210. Course Schedule II | Python | educative.io | Medium | 📌 Very Important. Check again. BFS, Topological Sort |
03 | 269. Alien Dictionary | Python | educative.io, Vid 1, Vid 2, Vid 3 | Hard | 📌 Very Important. Check again. BFS, Topological Sort |
04 | 444. Sequence Reconstruction | Python | educative.io | Medium/Hard | 📌 Check again. BFS, Topological Sort |
05 | 310. Minimum Height Trees | Python | educative.io | Hard | 📌 TODO: Check again, very hard, didn't get the intuition. BFS, Topological Sort |
06 | 329. Longest Increasing Path in a Matrix | Python | Official, Art 1, Art 2 | Hard | ** 📌 TODO: Not Done, very hard and important. DP, Topological Sort ** |
07 | 1203. Sort Items by Groups Respecting Dependencies | Python | Hard | 📌 TODO: Not Done, very hard, didn't get the intuition. BFS, Topological Sort | |
08 | 695. Max Area of Island | Python | --- | Medium | DFS |
09 | 200. Number of Islands | Python | Algoexpert.io - DFS, Union Find, Art 1 | Medium | DFS + DFS, Union Find |
10 | 305. Number of Islands II | Python | Union Find, Art 0, Art 1, Art 2, Art 3, Art 4, Art 5 | Hard | Union Find |
11 | 399. Evaluate Division | Python | Art 0, Art 1, Art 2, Art 3, Art 4, Art 5 | Medium | TODO: Solve it using Union Find |
12 | 841. Keys and Rooms | Python | codinginterviewclass.com, Art 1, Art 2 | Medium | BFS, DFS |
13 | 490. The Maze | Python | codinginterviewclass.com, Vid 1, Art 1, Art 2, Art 3, Art 4, Art 5 | Medium | Modified BFS and DFS |
14 | 130. Surrounded Regions | Python | codinginterviewclass.com, Art 1, Art 2 | Medium | TODO: Solve it using Union Find. Modified BFS and DFS |
15 | 127. Word Ladder | Python | codinginterviewclass.com, Official, Art 1 | Medium | Very important and tricky. Modified BFS. Shortest Path finding |
16 | 126. Word Ladder II | Python | codinginterviewclass.com, Official, Vid 1 | Hard | TODO: Not Done. Extremely tricky. Modified BFS. Learned Bidirectional Search |
17 | 785. Is Graph Bipartite? | Python | codinginterviewclass.com, Official | Medium | Important, Learned new things. Undirected Graph |
18 | 133. Clone Graph | Python | codinginterviewclass.com, Official | Medium | Important, Learned new things. Undirected Graph |
19 | 332. Reconstruct Itinerary | Python | Vid 1, Vid 2, Art 1, Art 2, Art 3, Art 4 | Medium | Important, Learned new things. Directed Graph. Eulerian path and top Sort |
20 | 1153. String Transforms Into Another String | Python | Vid 1, Vid 2, Art 1, Art 2, Art 3, Art 4, Art 5, Art 6 | Extremely Hard | TODO: Check again. Very Important and tricky, Learned new things. Digraph. |
21 | 743. Network Delay Time | Python | Official, Dijkstra 1, Dijkstra 2, Vid 1, Art 1, Art 2, Art 3, Art 4 | Medium | TODO: Check again. Very Important. Learned (Dijkstra, Bellman, Floyed). Check references section |
22 | 261. Graph Valid Tree | Python | Art 1, Art 2, Art 3, Art 4 | Medium | Important. BFS, DFS and Union Find |
23 | 1168. Optimize Water Distribution in a Village | Python | Art 1, Art 2, Art 3, Art 4 | Hard | TODO: Check AGain. Prim's and Kruskal's algorithm. Important. |
24 | 1197. Minimum Knight Moves | Python | Art 1 | Medium | TODO: Check AGain. Important. |
25 | 1066. Campus Bikes II | Python | Vid 1, Art 1 | Medium | 📌 TODO: CHECK Dijkstra approach again. Backtracking solution is getting TLE. Solve it and implement it with DP also. Very important |
Leetcode problems with solutions and tutorials/videos
# | 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 | --- | --- | --- | --- |
14. Backtracking
Leetcode problems with solutions and tutorials/videos
15. Greedy
Leetcode problems with solutions and tutorials/videos
Follow this golden rule to approach any DP problem.
Leetcode problems with solutions and tutorials/videos
Leetcode problems with solutions and tutorials/videos
# | 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 | 187. Repeated DNA Sequences | Python | Official | Medium | ⭐ 😭 Didn't understand, check again |
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 | 268. Missing Number | Python | Educative.io, Official | Easy | 📌 Learned few very important binary logic properties. Also check cyclic sort technique |
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 | 136. Single Number | Python | Educative.io | Easy | 📌 The key here is to practice bit operation, i ignore any other attempts |
11 | 137. Single Number II | Python | 1, 2, 3, Check discussion | Medium | ⭐ 😭 Didn't understand, check again |
12 | 260. Single Number III | Python | Educative.io | Medium | ⭐ Check again, very important |
13 | 476. Number Complement | Python | Educative.io | Easy | ⭐ Check again |
14 | 832. Flipping an Image | Python | Educative.io | Easy | ⭐ Check again |
77 Problems
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Invert_Binary_Tree | Python | |||
02 | Max_Path_Sum_In_Binary_Tree | Python | |||
03 | Iterative_In-order_Traversal | Python |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Kadane's_Algorithm | Python | |||
02 | Topological_Sort | Python |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Min_Heap_Construction | Python | Video 1 | ||
02 | Continuous_Median | Python | Video 1, Video 2 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Balanced Bracket | Python | |||
02 | Min_Max_Stack_Construction | Python |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | 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 |
Problem sstatement from AlgoExpert.io with solutions and tutorials/videos
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | Suffix_Trie_Construction | Python | |||
02 | Multi_String_Search | Python |
Some helpful links, channels, tutorials, blogs.
- 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
- 10 Steps to Solving a Programming Problem
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
- Magic Methods
- 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?
- Height, Depth and Level of a Tree
- What is the difference between tree depth and height?
- Graph Theory Playlist
- Graph Theory Playlist 2
- Union Find [Disjoint Set] Playlist
- Disjoint Sets Data Structure - Weighted Union and Collapsing Find
- Codinginterviewclass.com
- Single/All Source Shortest Path Algorithms: Dijkstra (1, 2), Bellman-Ford(1, 2), Floyd–Warshall(1, 2)
- Dijkstra’s Algorithm Vs Bellman-Ford Algorithm Vs Floyd Warshall Algorithm (1, 2, 3
- Minimum Spanning Tree Algorithm: Prim's (1, 2, Kruskal's (1, 2
- Kruskal's algorithm Vs Prim's algorithm (1, 2, 3
- 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
- The FAST method
- A good approach to attack DP
- Tabulation vs Memoization
- Memoization vs Tabulation
- 1D Subproblems vs. 2D Subproblems
- Memoization (1D, 2D and 3D)
- Introduction to Multi-dimensional Dynamic Programming
- Dynamic Programming Patterns - MUST READ
- My experience and notes for learning DP
- DP IS EASY! 5 Steps to Think Through DP Questions
- 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
- 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?