Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

nikitabuida/Algorithms

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


GitHub last commit GitHub repo size in bytes Contributors Forks Stargazers Issues MIT License LinkedIn leetcode badge leetcode badge leetcode badge Travis Travis Total visitor Visitors in today

Around 200 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.

Show your support by giving it a STAR

AboutTopicsTipsLeetCode.comAlgoExpert.ioReferences



About

I have solved quite a number of problems from several topics. See the below table for further details.

Languages

  • Python, Swift

Topics

  • 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...

Questions from

My other related repos

My leetcode account

Tips

  • 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.
  • ...


LeetCode

leetcode badge

# 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
23 912. Sort an Array (Merge Sort) Python --- Medium ---
24 1118. Number of Days in a Month Python --- Easy ---
# 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 ---

Graphs

(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 211. Add and Search Word. Data structure design Python Video 01, Video 02
02 37. Sudoku Solver Python Video 01, Video 02
03 52. N-Queens II Python Video 01, Video 02
04 784. Letter Case Permutation Python --- Easy Backtracking Fundamentals
05 22. Generate Parentheses Python Video 1, Article 1 Medium Backtracking Fundamentals
06 17. Letter Combinations of a Phone Number Python Video 1, Video 2 - paid course, Article 1 Medium Backtracking Fundamentals
07 46. Permutations Python Video 1 - paid course, Article 1, Article 2 Medium Backtracking Fundamentals
08 39. Combination Sum Python Article 1, Article 2 Medium Backtracking Fundamentals
09 79. Word Search Python Article 1 Medium Backtracking Fundamentals
10 78. Subsets Python Video 1, Video 2, Video 3, Article 1 Medium 📌 TODO: check bit manipulation
11 77. Combinations Python Video 1 - paid course Medium 📌 TODO: Not done. Hard to grasp. Check again
12 1066. Campus Bikes II Python Algo Notes Medium 📌 TODO: Backtracking solution is getting TLE. Solve it and implement it with DP also
13 1087. Brace Expansion Python --- Medium 📌 ---
14 1219. Path with Maximum Gold Python --- Medium 📌 ---
# 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 53. Maximum Subarray Python
02 518. Coin Change 2 Python
03 322. Coin Change Python
04 72. Edit Distance Python Video 01
05 70. Climbing Stairs Python
06 96. Unique Binary Search Trees Python Video 01, Video 02
07 95. Unique Binary Search Trees II Python
08 221. Maximal Square Python Video 01, Video 02
09 85. Maximal Rectangle Python Video 01
10 42. Trapping Rain Water Python Article 01 Hard 📌 Check stack and 2 pointers based solutions
11 300. Longest Increasing Subsequence Python Article 01 Medium 📌 Need to check Binary Search approach, which is a lot harder
12 1143. Longest Common Subsequence Python --- Medium 📌 Classic DP
13 5. Longest Palindromic Substring Python --- Medium 📌 Classic DP
14 1066. Campus Bikes II Python Medium 📌 TODO: Backtracking solution is getting TLE. Solve it and implement it with DP also
15 121. Best Time to Buy and Sell Stock Python Vid 1 Easy Fundamental
16 122. Best Time to Buy and Sell Stock II Python Video 01 Easy More like Greedy
17 123. Best Time to Buy and Sell Stock III Python Vid 1, Vid 2 Hard Fundamental
18 188. Best Time to Buy and Sell Stock IV Python Vid 1, Vid 2 Hard Getting "Memory Limit Exceeded"
19 309. Best Time to Buy and Sell Stock with Cooldown Python Must, Art0, Art1, Must 2 , Art 2, Art 3, Medium Very tricky, must check again. Couldn't solve
20 714. Best Time to Buy and Sell Stock with Transaction Fee Python Must Read , Art 2 Medium More like Greedy, but DP

Bit Manipulation

# 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


AlgoExpert

77 Problems

Arrays

# 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

Binary Search Tree

# 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

Binary Tree

# Title Solution Tutorial Level Remarks
01 Invert_Binary_Tree Python
02 Max_Path_Sum_In_Binary_Tree Python
03 Iterative_In-order_Traversal Python

Dynamic Programming

# 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

Famous Algorithm

# Title Solution Tutorial Level Remarks
01 Kadane's_Algorithm Python
02 Topological_Sort Python

Graphs

# 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

Heaps

# Title Solution Tutorial Level Remarks
01 Min_Heap_Construction Python Video 1
02 Continuous_Median Python Video 1, Video 2

Linked List

# 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

Recursion

# 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

Searching

# 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

Sorting

# 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

Stacks

# Title Solution Tutorial Level Remarks
01 Balanced Bracket Python
02 Min_Max_Stack_Construction Python

String

# 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

Tries

# Title Solution Tutorial Level Remarks
01 Suffix_Trie_Construction Python
02 Multi_String_Search Python


References

Some helpful links, channels, tutorials, blogs.

Strategies

  1. How a Googler solves coding problems
  2. Nail Every Coding Interview by Becoming Asymmetrical
  3. How to get into FAANG
  4. Preparing for Programming interview with Python
  5. The 30-minute guide to rocking your next coding interview
  6. Google Interview Part-1 , Google Interview Part-2, Google Interview Part-3, Final Part
  7. Amazon ও Google এ চাকরির সুযোগ পাওয়ার প্রস্তুতি পর্ব
  8. How to use LeetCode effectively
  9. How to solve ANY interview question
  10. How To Ace The Google Coding Interview - Complete Guide
  11. Software Engineering Interviews: The Golden Path To Passing
  12. A MUST READ

Courses/Books

  1. Data Structures in Python: An Interview Refresher
  2. Grokking the Coding Interview: Patterns for Coding Questions
  3. Grokking Dynamic Programming Patterns for Coding Interviews
  4. Coding Interview Class
  5. 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.

  1. itertools - Functions creating iterators for efficient looping - They will help you, more often than you think
  2. collections - High-performance container datatypes - Believe me, this is pretty awesome
  3. heapq - Heap queue algorithm - Obviously, we don't have to hand-code heaps anymore
  4. bisect - Array bisection algorithm - Binary Search, simplified
  5. Set
  6. Dict - Now on, hash Tables are fun to work with
  7. Sorting - Don't participate in competitions without reading this completely.
  8. Start using lambda extensively
  9. functools
  10. Apart from these, all the builtin methods of default containers.
  11. Understanding slice notation - you will need/use it more than you can imagine

Channels

  1. Tushar Roy - Coding Made Simple
  2. Back To Back SWE
  3. William Fiset
  4. Irfan Baqui

Tree (Tree, BST, BIT, Segment Tree, N-aray Tree, Trie etc)

  1. Fenwick Tree or Binary Indexed Tree - youtube
  2. Binary Indexed Tree or Fenwick Tree - geeksforgeeks
  3. Binary Indexed Tree or Fenwick Tree - topcoder
  4. Segment Tree Range Minimum Query - youtube
  5. Segment Tree | Set 1 (Sum of given range) - geeksforgeeks
  6. Practical Data Structures for Frontend Applications: When to use Segment Trees
  7. What is the difference between a binary indexed tree and a segment tree?
  8. How does one decide when to use a Segment Tree or Fenwick Tree?
  9. 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)

  1. Graph Theory Playlist
  2. Union Find [Disjoint Set] Playlist
  3. Disjoint Sets Data Structure - Weighted Union and Collapsing Find

Bit Manipulation

  1. Bit Manipulation - youtube
  2. Conversion of Binary, Octal and Hexadecimal Numbers
  3. Your guide to Bit Manipulation
  4. Python Bitwise Operators
  5. Add Two Numbers Without The "+" Sign (Bit Shifting Basics)
  6. Binary Arithmetic
  7. 1’s and 2’s complement of a Binary Number
  8. What is “2's Complement”?
  9. Bits manipulation (Important tactics)
  10. Bit Manipulation
  11. Python Bitwise Operators
  12. XOR - The magical bitwise operator
  13. A summary: how to use bit manipulation to solve problems easily and efficiently - leetcode
  14. Bit Manipulation 4% of LeetCode Problems
  15. Coding Interview University - Bitwise operations
  16. Mask (computing)
  17. What is Bit Masking?
  18. Understanding Bit masks
  19. Bitmasks: A very esoteric (and impractical) way of managing booleans
  20. Hacker’s Delight - BOOK
  21. Bitwise operators — Facts and Hacks
  22. Signed number representations

Dynamic Programming

  1. The FAST method
  2. A good approach to attack DP
  3. Tabulation vs Memoization
  4. Memoization vs Tabulation

Greedy

  1. Greedy Method - Introduction
  2. Introduction to Greedy Method
  3. Introduction to Greedy Algorithms | GeeksforGeeks
  4. Basics of Greedy Algorithms
  5. When to try greedy algorithms on problems?
  6. How to spot a “greedy” algorithm?

DP VS Greedy

  1. Greedy Algorithm and Dynamic Programming
  2. Greedy approach vs Dynamic programming
  3. What is the difference between dynamic programming and greedy approach?

Backtracking

  1. Backtracking - wiki
  2. Backtracking | Introduction
  3. Introduction to Backtracking - Brute Force Approach
  4. Branch and Bound Introduction
  5. The Backtracking Blueprint: The Legendary 3 Keys To Backtracking Algorithms
  6. Backtracking explained
  7. Foundation of algorithms - Chapter 5 (Backtracking) notes
  8. Backtracking Search Algorithms

Recursion

  1. Learning to think with recursion, part 1
  2. Learning to think with recursion, part 2
  3. What makes a data structure recursive?
  4. Binary Tree as a Recursive Data Structure
  5. Recursion Visualizer - use Viz Mode
  6. Thinking Recursively in Python
  7. Breaking out of a recursive function?
  8. Why does recursion return the first call in the stack and not the last?

About

leetcode.com , algoexpert.io solutions in python and swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.1%
  • Swift 2.9%