Code practice link
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ โโโ | Leetcode | ||
๐ | โ โโโ | Leetcode | ||
๐ด | โ โโโ | Leetcode |
- โ /โ๏ธ For finished
- ๐ท For working in progress
- โ For unfinished due to complicity or challenging
- โFor marking good questions
- โwith doubt or unfinished
StrikedthroughFor not bothering (e.g. too easy)MARK
in code for paying extra attention
- ๐ข(Easy)
- ๐ (Medium)
- ๐ด(Hard) ๐คจ
Since I use kotlin, I have created some convenient utility functions, mostly for testing/debugging purpose. (I might just create a branch with just the utility functions, however.. )
Note: To enable assertion for kotlin, pass in -ea
as jvm launch argument, see this link
Other than those listed below, check out _util.kt for more
- Run timed tests on a list of method variable. Sample usage checkout this Update: I noticed that this method may not be accurate, not sure of the cause
@OptIn(ExperimentalTime::class)
inline fun<reified T : KCallable<*>, reified R> List<T>.runTimedTests(
testName: String? = Thread.currentThread().stackTrace.getOrNull(1)?.className?.split("$", limit = 0)?.get(0),
printTime: Boolean = true,
block: T.()->R
) {
forEachIndexed { index, it ->
val timeValue = measureTimedValue{ it.block() }
val prefix = if (testName.isNullOrEmpty()) "" else "${testName}."
if (printTime) println("execution for ${prefix}${it.name} finished, took ${timeValue.duration.inWholeNanoseconds} Nanoseconds")
}
}
Sample print out:
execution for _2022._05.Leetcode_15.MY1.threeSum finished, took 476348 Nanoseconds
execution for _2022._05.Leetcode_15.MY1.threeSum finished, took 423606 Nanoseconds
execution for _2022._05.Leetcode_15.MY2.threeSum finished, took 435733 Nanoseconds
- Assertion (assertEqual)
test() assertEqual "expected" // for single answer
test().assertEqual("possible_output1", "possible_output2") // for multiple correct answers
- Build-in data types
- Node (
typealias IntNode = Node<Int>
) and some built-in functions, e.g:fun <T> linkedNodesOf(vararg nodes: T) : Node<T>
usage:linkedNodesOf(1, 2, 3)
to create a linked nodes like1 -> 2 -> 3
fun <T> Node<T>.toList() : List<T>
usage:linkedNodesOf(1, 2, 3).toList()
gets:[1,2,3]
fun <T, R> Node<T>.mapValue(transform: ((T)->R)) : List<R>
usage:linkedNodesOf(1, 2, 3).mapValue{ it * 2 }
gets[2,4,6]
- others see this file: Node
- Node (
youngyangyang04/leetcode-master/0001.ไธคๆฐไนๅ.md ยท GitHub
Marks | link | Notes |
---|---|---|
๐ขโ | 1. Two Sum | |
๐ขโ | 342. Valid Anagram | |
๐ขโ | 349. Intersection of Two Arrays | |
๐ข | ||
๐ขโ | 49. Group Anagrams |
youngyangyang04/leetcode-master/0005.ๆ้ฟๅๆๅญไธฒ.md ยท GitHub
Marks | link | Notes |
---|---|---|
๐ โ | 647. Palindromic Substrings | |
๐ โโ | 5. Longest Palindromic Substring |
youngyangyang04/leetcode-master/0005.ๆ้ฟๅๆๅญไธฒ.md ยท GitHub
Difficulty | Marks | link | Notes |
---|---|---|---|
Medium | โ โ | 5. Longest Palindromic Substring [leetcode] [git] | |
Medium | โ | 15. 3Sum ๐๐๐ [leetcode] [git] | My4 not done |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
Easy | ๐ โ | |||
Medium | ๐ขโ | 17. Letter Combinations of a Phone Number | Leetcode Github | Didn't read the sample code since it didn't take me too much thinking to solve the question, but it might worth a read |
Medium | Skipped for now | 18. 4Sum ๐๐๐๐ | Leetcode Github | |
Medium | ๐ โ | 19. Remove Nth Node From End of List | Leetcode Github |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
Easy | ๐ขโ | 21. Merge Two Sorted Lists | Leetcode labuladong | Sample1 is interesting (recursion) |
Easy | ๐ขโ | 141. Linked List Cycle | Leetcode | |
Medium | โ | 142. Linked List Cycle II | Leetcode labuladong |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
Hard | ๐ขโ | 23. Merge k Sorted Lists | Leetcode labuladong | Need to read the sample code |
Easy | โ | 160. Intersection of Two Linked Lists | Leetcode labuladong | Sample1 is interesting (recursion) |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
Easy | ๐ข | 876. Middle of the Linked List | Leetcode | Faster than 100% submission ๐ข๐ข |
Medium | โ | 92. Reverse Linked List II | Leetcode | My2 |
Easy | ๐ โ | 206. Reverse Linked List | Leetcode | Need to check sample and read this and read S1 |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
Hard | ๐ดโโโ | 25. Reverse Nodes in k-Group | Leetcode |
TODO:
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ | 234. Palindrome Linked List | Leetcode | |
๐ข | โ | 26. Remove Duplicates from Sorted Array | Leetcode | |
๐ข | โ | 27. Remove Element | Leetcode | |
๐ข | โ | 83. Remove Duplicates from Sorted List | Leetcode |
TODO: Leetcode_710
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ ๐ข | 167. Two Sum II - Input Array Is Sorted | Leetcode | |
๐ข | โ | 283. Move Zeroes | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ | 344. Reverse String | Leetcode | |
๐ข | โ | 303. Range Sum Query - Immutable | Leetcode | |
๐ | โ | 304. Range Sum Query 2D - Immutable | Leetcode |
Leetcode 370: Range Addition
Difficulty | Marks | Name | link | Notes | ||
---|---|---|---|---|---|---|
๐ | โ | Leetcode | Put off for now | |||
๐ | โ ๐ข | 1094. Car Pooling | Leetcode | |||
๐ | โ | Leetcode | ||||
๐ | โ | 48. Rotate Image | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 54. Spiral Matrix | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 59. Spiral Matrix II | Leetcode | |
๐ | โ โ | 3. Longest Substring Without Repeating Characters | Leetcode | TODO: read explanation |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ด | 76. Minimum Window Substring | Leetcode | ||
๐ | 34. Find First and Last Position of Element in Sorted Array | Leetcode | ||
๐ | 1109. Corporate Flight Bookings | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 11. Container With Most Water | Leetcode | |
๐ด | โ โโโ | 42. Trapping Rain Water | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 238. Product of Array Except Self | Leetcode | |
๐ข | โ | 217. Contains Duplicate | Leetcode | |
๐ | โ | 347. Top K Frequent Elements | Leetcode | 1. Heatmap, 2. bucket list/sort |
๐ข | โ | 125. Valid Palindrome | Leetcode | |
๐ | โ | 271. Encode and Decode Strings | Lintcode_659 |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 128. Longest Consecutive Sequence | Leetcode | |
๐ข | โ | 121. Best Time to Buy and Sell Stock | Leetcode | |
๐ | โ โ | 424. Longest Repeating Character Replacement | Leetcode | |
๐ | โ | 567. Permutation in String | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ด | โ โโโ | 239. Sliding Window Maximum | Leetcode | |
๐ข | โ | 20. Valid Parentheses | Leetcode | |
๐ | โ โ | 155. Min Stack | Leetcode | The use of miniStack in S1 and S2 |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 150. Evaluate Reverse Polish Notation | Leetcode | |
๐ | โ โ | 22. Generate Parentheses | Leetcode | |
๐ข | โ โโโ | 496. Next Greater Element I | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 739. Daily Temperatures | Leetcode | |
๐ | โ | 853. Car Fleet | Leetcode |
| |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ด | โ | 84. Largest Rectangle in Histogram | Leetcode | |
๐ข | โ | 704. Binary Search | Leetcode | |
๐ | โ | 74. Search a 2D Matrix | Leetcode | |
๐ | โ โ | 875. Koko Eating Bananas | Leetcode | |
๐ | โ | 33. Search in Rotated Sorted Array | Leetcode | |
๐ข | โ โโโ | Leetcode | ||
๐ | โ โโโ | Leetcode | ||
๐ด | โ โโโ | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ โโโ | 143. Reorder List | Leetcode | |
๐ข | โ โโโ | Leetcode | ||
๐ | โ โโโ | Leetcode | ||
๐ด | โ โโโ | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 138. Copy List with Random Pointer | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 2. Add Two Numbers | Leetcode | |
๐ | โ | 287. Find the Duplicate Number | Leetcode | |
๐ | โ | 146. LRU Cache | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ | 226. Invert Binary Tree | Leetcode | |
๐ข | โ โ | 104. Maximum Depth of Binary Tree | Leetcode | |
๐ข | โ | 110. Balanced Binary Tree | Leetcode | |
๐ข | โ | 100. Same Tree | Leetcode | |
๐ข | โ โ | 572. Subtree of Another Tree | Leetcode |
- 572: can use a utility method
isSameTree
to check or need to be careful (see solution)
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ | 235. Lowest Common Ancestor of a Binary Search Tree | Leetcode | |
๐ข | โ โโโ | 703. Kth Largest Element in a Stream | Leetcode | |
๐ข | โ | 1046. Last Stone Weight | Leetcode | |
๐ข | โ | 70. Climbing Stairs | Leetcode | |
๐ข | โ | 746. Min Cost Climbing Stairs | Leetcode | |
๐ข | โ โโโ | Leetcode | ||
๐ | โ โโโ | Leetcode | ||
๐ด | โ โโโ | Leetcode |
- 235:
Binary search tree
: left <=val
<= right - 746: Build an array dp where dp[i] is the minimum cost to climb to the top starting from the ith staircase.
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ | 136. Single Number | Leetcode | |
๐ข | โ โ | 191. Number of 1 Bits | Leetcode | |
๐ข | โ | 338. Counting Bits | Leetcode | |
๐ข | โ | 190. Reverse Bits | Leetcode | |
๐ข | โ โโโ | 268. Missing Number | Leetcode |
- 191: use mod n = n % 2
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 208. Implement Trie (Prefix Tree) | Leetcode | |
๐ | โ | 211. Design Add and Search Words Data Structure | Leetcode | |
๐ | โ | 981. Time Based Key-Value Store | Leetcode | |
๐ | โ | 973. K Closest Points to Origin | Leetcode | |
๐ | โ | 215. Kth Largest Element in an Array | Leetcode | |
๐ | โ | 78. Subsets | Leetcode | try to solve with single res: ArrayList |
๐ | โ โโโ | 39. Combination Sum | Leetcode | S1 |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 46. Permutations | Leetcode | |
๐ | โ โโโ | 90. Subsets II | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 40. Combination Sum II | Leetcode | |
๐ | โ โ | 200. Number of Islands | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ โโโ | 695. Max Area of Island | Leetcode | |
๐ | โ โโโ | 133. Clone Graph | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 417. Pacific Atlantic Water Flow | Leetcode | revert: ocean to land |
๐ | โ โโโ | 130. Surrounded Regions | Leetcode |
Note:
- 130: reverse thinking, thanks all non-surrounded region to T and change all O to X then change Ts back to O
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ โ | 198. House Robber | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ โโโ | 322. Coin Change | Leetcode | |
๐ | โ โโโ | 91. Decode Ways | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 36. Valid Sudoku | Leetcode | |
๐ | โ โโโ | 53. Maximum Subarray | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ โ | 134. Gas Station | Leetcode | |
๐ | โ โโ | 55. Jump Game | Leetcode | |
๐ | โ โ | 45. Jump Game II | Leetcode |
Notes:
- 55: M4
- 134: S1
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 846. Hand of Straights | Leetcode | |
๐ | โ โ | 57. Insert Interval | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ โโโ | 102. Binary Tree Level Order Traversal | Leetcode |
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ | โ | 199. Binary Tree Right Side View | Leetcode | |
๐ | โ | 1448. Count Good Nodes in Binary Tree | Leetcode | |
๐ | โ | 98. Validate Binary Search Tree | Leetcode | |
๐ | โ โ | 230. Kth Smallest Element in a BST | Leetcode | |
๐ | โ โโโ | 105. Construct Binary Tree from Preorder and Inorder Traversal | Leetcode | |
๐ | โ โโโ | 211. Design Add and Search Words Data Structure | Leetcode | |
๐ | โ โ | 621. Task Scheduler | Leetcode |
Notes:
- bfs - order level traversal
- 98: binary search tree - sorted order
- 230: solution
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ โโโ | Leetcode | ||
๐ | โ โ | 355. Design Twitter | Leetcode | |
๐ | โ | 332. Reconstruct Itinerary | Leetcode | |
๐ | โ โ | 1584. Min Cost to Connect All Points | Leetcode |
Notes:
- 1584: Read S2 and link
Difficulty | Marks | Name | link | Notes |
---|---|---|---|---|
๐ข | โ โโโ | Leetcode | ||
๐ | โ | 143. Reorder List | Leetcode | |
๐ | โ | 146. LRU Cache | Leetcode | |
๐ | โ | 23. Merge k Sorted Lists | Leetcode | |
๐ด | โ | 25. Reverse Nodes in k-Group | Leetcode | |
๐ | 211. Design Add and Search Words Data Structure | Leetcode | ||
๐ | โโโ | 4. Median of Two Sorted Arrays | Leetcode | |
๐ | โ | 130. Surrounded Regions | Leetcode |
Notes:!!
- 143: slow -> 0 and fast -> 1, fast jumps two steps while slow jumps one, when fast became null slow is at the end of the first half
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ โโโ | 743. Network Delay Time | Leetcode |
๐ | โ โโโ | 295. Find Median from Data Stream | Leetcode |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | 79. Word Search | Leetcode |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | 131. Palindrome Partitioning | Leetcode |
๐ | โ โโโ | 17. Letter Combinations of a Phone Number | Leetcode |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | 663 ยท Walls and Gates | Leetcode |
๐ | โ | 207. Course Schedule | Leetcode |
- 207: S1
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ โโโ | 684. Redundant Connection | [Leetcode](// https://leetcode.com/problems/redundant-connection/) |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | 2385. Amount of Time for Binary Tree to Be Infected | Leetcode |
- 2385: S1
Difficulty | Marks | Name | link |
---|---|---|---|
๐ด | โ โโโ | 4. Median of Two Sorted Arrays | Leetcode |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ โโโ | 8. String to Integer (atoi) | Leetcode |
๐ | โ โโโ | 56. Merge Intervals | Leetcode |
- 8: stupid ass question, not worth looking at
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | 435. Non-overlapping Intervals | Leetcode |
๐ | โ โโโ | Lintcode 919 ยท Meeting Rooms II | Leetcode youtube |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | Leetcode | |
๐ | โ | 73. Set Matrix Zeroes | Leetcode |
๐ | โ | 50. Pow(x, n) | Leetcode |
๐ | โ | 371. Sum of Two Integers | Leetcode |
๐ข | โ | 202. Happy Number | Leetcode |
๐ข | โ | 66. Plus One | Leetcode |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ | 338. Counting Bits | Leetcode |
๐ | โ โโโ | 91. Decode Ways | Leetcode |
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ โโโ | 213. House Robber II | Leetcode |
- 213: run house robber 1 two times with either first house included or the last
Difficulty | Marks | Name | link |
---|---|---|---|
๐ | โ โโโ | 322. Coin Change | Leetcode |
Diff | Marks | Name | link |
---|---|---|---|
๐ | โ โ | 743. Network Delay Time | Leetcode |
๐ | โ | 209. Minimum Size Subarray Sum | Leetcode |
๐ | โ โโโ | Leetcode | |
๐ | โ โโโ | Leetcode | |
๐ | โ โโโ | Leetcode | |
๐ข | โ โโโ | Leetcode | |
๐ข | โ โโโ | 977. Squares of a Sorted Array | Leetcode |
๐ด | โ โโโ | Leetcode |
- 209: sliding window (left/right pointers)
Diff | Marks | Name | link |
---|---|---|---|
๐ | โ โโโ | Leetcode | |
๐ | โ โโโ | Leetcode | |
๐ | โ โโโ | Leetcode | |
๐ | โ โโโ | Leetcode | |
๐ข | โ โโโ | Leetcode | |
๐ด | โ โโโ | Leetcode |
- Quick sort
- Quick select
- depth first search
- when there are multiple same value (not distinct), how to get the left most index of the given value (or right)
l < r
vsl <= r
- you can go either way
- starting from position 0, and for each layer down the line you can either add or not add the next element (Leetcode_46), or
- starting form all the element including, you can have any many children as the element, and for each child, consider the corresponding element removed (Leetcode_90)
- LeetCode Top 100 Problem Selection | Step-by-step Data Science
- GitHub - youngyangyang04/leetcode-master: ๐ ใไปฃ็ ้ๆณๅฝใLeetCode ๅท้ขๆป็ฅ๏ผ200้็ปๅ ธ้ข็ฎๅท้ข้กบๅบ
- LABULADONG ็็ฎๆณ็ฝ็ซ
- https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/
- https://leetcode.com/problems/graph-valid-tree/
- https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
- https://leetcode.com/problems/palindrome-partitioning/submissions/
- https://leetcode.cn/problems/construct-binary-tree-from-preorder-and-inorder-traversal/