[](https://leetcode.com/ParthoBiswas007/) Leetcode.com and 77 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.
- 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 | 1. Two Sum | Python, Swift | --- | --- | ✅ 📌 ⭐ 😭 🧐 😎 |
02 | 485. Max Consecutive Ones | Swift | |||
03 | 476. Number Complement | Swift | |||
04 | 461. Hamming Distance | Swift | |||
05 | 9. Palindrome Number | Python | |||
06 | 88. Merge Sorted Array | Python | |||
07 | 811. Subdomain Visit Count | Python | |||
08 | 771. Jewels and Stones | Python | |||
09 | 414. Third Maximum Number | Python | |||
10 | 259. 3Sum Smaller | Python | |||
11 | 16. 3Sum Closest | Python | |||
12 | 15. 3Sum | Python | |||
13 | 118. Pascal's Triangle | Python | |||
14 | 119. Pascal's Triangle II | Python | |||
15 | 238. Product of Array Except Self | Python | |||
16 | 724. Find Pivot Index | Python | |||
17 | 747. Largest Number At Least Twice of Others | Python | |||
18 | 581. Shortest Unsorted Continuous Subarray | Python | |||
19 | 904. Fruit Into Baskets | Python | Article, Video 1, Video 2 | ||
20 | 56. Merge Intervals | Python | Article | ||
21 | 334. Increasing Triplet Subsequence | Python | --- | Medium | --- |
22 | 792. Number of Matching Subsequences | Python | Official | Medium | Very tricky. Check again |
# | 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 | 912. Sort an Array (Merge Sort) | Python |
# | 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 |
# | 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 | 253_Meeting_Rooms_II | Python | Official | Medium | --- |
02 | 347. Top K Frequent Elements | Python | Helper 1, Helper 2, heapq, Counter | Medium | --- |
# | 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 | --- |
# | Title | Solution | Tutorial | Level | Remarks |
---|
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 200. Number of Islands | Python |
# | 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 | Medium | 📌 Extremely tricky. Not done. Check later |
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 | 📌 |
# | 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 |
# | Title | Solution | Tutorial | Level | Remarks |
---|---|---|---|---|---|
01 | 1118. Number of Days in a Month | Python |
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
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
Channels
Graphs (Tree, BST, BIT, Segment Tree, 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?
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?