jz33 / LeetCodeSolutions

Solution for Leetcode questions written in C, C++, Python, Java, Javascript, Golang, C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LeetCodeSolutions

Solution for LeetCode questions written mostly in Python3, also in C, C++, Java, Javascript, Typescript, Golang, C#

Category of some questions (in work):

O(log(n))

Binary Search

33. Search in Rotated Sorted Array [Facebook]
34. Find First and Last Position of Element in Sorted Array [Facebook]
35. Search Insert Position
153. Find Minimum in Rotated Sorted Array
162. Find Peak Element [Facebook]
300. Longest Increasing Subsequence
658. Find K Closest Elements [Facebook]
1060. Missing Element in Sorted Array [Facebook]\

Binary Search on Matrix

74. Search a 2D Matrix
378. Kth Smallest Element in a Sorted Matrix [Facebook]
1901. Find a Peak Element II [Facebook]

Binary Guess

875. Koko Eating Bananas
1011. Capacity To Ship Packages Within D Days [Facebook]\

O(n)

Two Pointers Both Sides

1. Two Sum
5. Longest Palindromic Substring
11. Container With Most Water
15. 3Sum [Facebook]
42. Trapping Rain Water
125. Valid Palindrome [Facebook]
167. Two Sum II - Input array is sorted
259. 3Sum Smaller
680. Valid Palindrome II [Facebook]

Two Pointers One Side

408. Valid Word Abbreviation [Facebook]
622. Design Circular Queue
826. Most Profit Assigning Work [DoorDash]

Two Pointers Merge

2. Add Two Numbers [Amazon]
415 Add Strings [Facebook]
1570. Dot Product of Two Sparse Vectors [Facebook]
1662. Check If Two String Arrays are Equivalent
1868. Product of Two Run-Length Encoded Arrays [Facebook]

Hashmap

128. Longest Consecutive Sequence
380. Insert Delete GetRandom O(1) [Facebook**]
383. Ransom Note [Facebook]
398. Random Pick Index [Facebook]
763. Partition Labels
791. Custom Sort String[Facebook]
1657. Determine if Two Strings Are Close
2365. Task Scheduler II [Facebook]

Prefix Sum or Prefix Max

303. Range Sum Query - Immutable
304. Range Sum Query 2D - Immutable [Facebook]
325. Maximum Size Subarray Sum Equals k
523. Continuous Subarray Sum [Facebook]
528. Random Pick with Weight [Facebook]
560. Subarray Sum Equals K [Facebook]
689. Maximum Sum of 3 Non-Overlapping Subarrays [Facebook]

Sliding Window

3. Longest Substring Without Repeating Characters
76. Minimum Window Substring [Facebook]
209. Minimum Size Subarray Sum
239. Sliding Window Maximum [Facebook]
346. Moving Average from Data Stream [Facebook]
713. Subarray Product Less Than K
1004. Max Consecutive Ones III [Facebook]
1358. Number of Substrings Containing All Three Characters [Facebook]
2461. Maximum Sum of Distinct Subarrays With Length K [Facebook]

Monotonic Stack

84. Largest Rectangle in Histogram [Facebook]
155. Min Stack
402. Remove K Digits
1944. Number of Visible People in a Queue [Facebook]

Calculator

224. Basic Calculator [Facebook]
227. Basic Calculator II [Facebook]
394. Decode String
772. Basic Calculator III

Stack on Parentheses

20. Valid Parentheses
32. Longest Valid Parentheses
71. Simplify Path [Facebook]
636. Exclusive Time of Functions [Facebook]
735. Asteroid Collision
921. Minimum Add to Make Parentheses Valid [Facebook]
1047. Remove All Adjacent Duplicates In String [Facebook]
1209. Remove All Adjacent Duplicates in String II [Facebook]
1249. Minimum Remove to Make Valid Parentheses [Facebook]
1541. Minimum Insertions to Balance a Parentheses

Intervals

56. Merge Intervals
57. Insert Intervals
253. Meeting Rooms II [Facebook]
435. Non-overlapping Intervals
986. Interval List Intersections [Facebook, union not intersection]
3009. Maximum Number of Intersections on the Chart

1-D Iteration or Greedy

41. First Missing Positive [Facebook]
45. Jump Game II
68. Text Justification
121. Best Time to Buy and Sell Stock
229. Majority Element II
384. Shuffle an Array
605. Can Place Flowers [Facebook]
670. Maximum Swap [Facebook]
739. Daily Temperatures
1762. Buildings With an Ocean View [Facebook]
2468. Split Message Based on Limit

Hashing

49. Group Anagrams[Amazon]
249. Group Shifted Strings [Facebook]

Bucket Sort

358. Rearrange String k Distance Apart
621. Task Scheduler
767. Reorganize String [Amazon]

O(nlog(n))

Heap

23. Merge k Sorted Lists [Facebook]
88. Merge Sorted Array [Facebook]
215. Kth Largest Element in an Array [Facebook]
218. The Skyline Problem
295. Find Median from Data Stream
347. Top K Frequent Elements [Facebook]
373. Find K Pairs with Smallest Sums
973. K Closest Points to Origin [Facebook]

Sorted Map

480. Sliding Window Median
729. My Calendar I
2034. Stock Price Fluctuation

Divide and Conquer

4. Median of Two Sorted Arrays [Facebook]
215. Kth Largest Element in an Array [Facebook]
315. Count of Smaller Numbers After Self
493. Reverse Pairs

Trie

208. Implement Trie
588. Design In-Memory File System
642. Design Search Autocomplete System
676. Implement Magic Dictionary

O(n^2)

2-D Matrix Iterations

36. Valid Sudoku
48. Rotate Image
73. Set Matrix Zeroes
54. Spiral Matrix
240. Search a 2D Matrix II
419. Battleships in a Board
463. Island Perimeter
498. Diagonal Traverse [Facebook]
766. Toeplitz Matrix [Facebook]
1424. Diagonal Traverse II [Facebook]

Dynamic Programming

Constant States Dynamic Programming

53. Maximum Subarray
91. Decode Ways
152. Maximum Product Subarray
198. House Robber
1186. Maximum Subarray Sum with One Deletion

1-D Cache Incremental Dynamic Programming

39. Combination Sum [Facebook]
40. Combination Sum II [Facebook]
139. Word Break [Facebook]
140. Word Break II [Facebook]
322. Coin Change
377. Combination Sum IV
518. Coin Change 2
1043. Partition Array for Maximum Sum
1235. Maximum Profit in Job Scheduling [DoorDash]

1-D Cache Replacement Dynamic Programming

22. Generate Parentheses
40. Combination Sum II
90. Subsets II
494. Target Sum [Facebook]

2-D Cache Dynamic Programming

63. Unique Paths II [Facebook]
64. Minimum Path Sum [Facebook]
72. Edit Distance
115. Distinct Subsequences
188. Best Time to Buy and Sell Stock IV
221. Maximal Square
516. Longest Palindromic Subsequence
718. Maximum Length of Repeated Subarray
1143. Longest Common Subsequence
1216. Valid Palindrome III [Facebook]

Top down Dynamic Programming (Recursive + Memorization)

10. Regular Expression Matching
47. Permutations II
93. Restore IP Addresses
282. Expression Add Operators [Facebook]
301. Remove Invalid Parentheses [Facebook]
486. Predict the Winner
996. Number of Squareful Arrays
2060. Check if an Original String Exists Given Two Encoded Strings

Single Linked List

19. Remove Nth Node From End of List [Facebook]
138. Copy List with Random Pointer [Facebook]
141. Linked List Cycle
160. Intersection of Two Linked Lists
206. Reverse Linked List
234. Palindrome Linked List [Facebook]
708. Insert into a Sorted Circular Linked List [Facebook]

Double Linked List

146. LRU Cache dll + hashmap
432. All O`one Data Structure dll + hashmap
460. LFU Cache dll matrix + hashmap

Tree

Preorder Traversal

100. Same Tree
101. Symmetric Tree
112. Path Sum
113. Path Sum II
129 Sum Root to Leaf Numbers [Facebook]
144. Binary Tree Preorder Traversal
199. Binary Tree Right Side View [Facebook]
339. Nested List Weight Sum [Facebook]
341. Flatten Nested List Iterator
437. Path Sum III
545. Boundary of Binary Tree
863. All Nodes Distance K in Binary Tree[Facebook]
938. Range Sum of BST [Facebook]
958. Check Completeness of a Binary Tree [Facebook]

Inorder Traversal, Binary Search Tree

94. Binary Tree Inorder Traversal
98. Validate Binary Search Tree
100. Same Tree
173. Binary Search Tree Iterator [Facebook]
230. Kth Smallest Element in a BST
270. Closest Binary Search Tree Value [Facebook]
426. Convert Binary Search Tree to Sorted Doubly Linked List [Facebook]
1008. Construct Binary Search Tree from Preorder Traversal

Postorder Traversal

95. Unique Binary Search Trees II
104. Maximum Depth of Binary Tree
111. Minimum Depth of Binary Tree
124. Binary Tree Maximum Path Sum [Facebook]
145. Binary Tree Postorder Traversal
543. Diameter of Binary Tree [Facebook]
865. Smallest Subtree with all the Deepest Nodes
968. Binary Tree Cameras [Facebook]
2265. Count Nodes Equal to Average of Subtree

LCA

235. Lowest Common Ancestor of a Binary Search Tree [Facebook]
236. Lowest Common Ancestor of a Binary Tree [Facebook]
1644. Lowest Common Ancestor of a Binary Tree II [Facebook]
1650. Lowest Common Ancestor of a Binary Tree III [Facebook]
1676. Lowest Common Ancestor of a Binary Tree IV

Level Order Traversal

102. Binary Tree Level Order Traversal
103. Binary Tree Zigzag Level Order Traversal
226. Invert Binary Tree
314. Binary Tree Vertical Order Traversal [Facebook]
987. Vertical Order Traversal of a Binary Tree [Facebook]

Tree constructions and serializations

105. Construct Binary Tree from Preorder and Inorder Traversal
106. Construct Binary Tree from Inorder and Postorder Traversal
297. Serialize and Deserialize Binary Tree
428. Serialize and Deserialize N-ary Tree[Facebook]
536. Construct Binary Tree from String
889. Construct Binary Tree from Preorder and Postorder Traversal

Graph

BFS on Matrix

200. Number of Islands
286. Walls and Gates
317. Shortest Distance from All Buildings [Facebook]
329. Longest Increasing Path in a Matrix [Facebook]
827. Making A Large Island [Facebook]
1091. Shortest Path in Binary Matrix [Facebook]
1293. Shortest Path in a Grid with Obstacles Elimination

BFS on Graph

17. Letter Combinations of a Phone Number [Facebook]
126. Word Ladder
785. Is Graph Bipartite
815. Bus Routes\

BFS with Dijkstra E * log(V)

490. The Maze
778. Swim in Rising Water
787. Cheapest Flights Within K Stops
1631. Path With Minimum Effort

DFS or Backtrack on Matrix

51. N-Queens
79. Word Search
200. Number of Islands
489. Robot Room Cleaner [Facebook]
694. Number of Distinct Islands

DFS or Backtrack on Graph

77. Combinations
133. Clone Graph
332. Reconstruct Itinerary [Facebook] # Euler path
691. Stickers to Spell Word [Facebook]
2097. Valid Arrangement of Pairs # Euler path

Union Find

261. Graph Valid Tree
305. Number of Islands II
323. Number of Connected Components in an Undirected Graph
547. Number of Provinces
684. Redundant Connection
721. Accounts Merge [Facebook]\

Topological Sort O(E + V)

210. Course Schedule II
269. Alien Dictionary [Facebook]
310. Minimum Height Trees [Facebook]
2050. Parallel Courses III

Special Graph Algorithms

834. Sum of Distances in Tree # Tree DP
1168. Optimize Water Distribution in a Village # Union Find + Kruskal
1192. Critical Connections in a Network # Tarjan
1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance # Floyd-Warshall

Math, Numbers, Binary or Geometry

8. String to Integer (atoi)
12. Integer to Roman
13. Roman to Integer [Amazon]
29. Divide Two Integers [Facebook]
31. Next Permutation [Facebook]
50. Pow(x, n) [Facebook]
65. Valid Number [Facebook]
78. Subsets [Facebook]
150. Rectangle Area
231. Power of Two
268. Missing Number
273. Integer to English Words
296. Best Meeting Point [Facebook]
633. Sum of Square Numbers

About

Solution for Leetcode questions written in C, C++, Python, Java, Javascript, Golang, C#


Languages

Language:Python 79.4%Language:TypeScript 9.6%Language:Java 6.2%Language:C++ 2.5%Language:C 0.9%Language:JavaScript 0.8%Language:Go 0.4%Language:C# 0.1%Language:Shell 0.1%Language:Ruby 0.0%