- ✅/✔️ For finished
- 👷 For working in progress
- ❌ For unfinished due to complicity or challenging
- ❗For marking good questions
- ❓with doubt or unfinished
Strikedthrough For 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)
inlinefun<reifiedT : KCallable<*>, reifiedR> 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 like 1 -> 2 -> 3fun <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
youngyangyang04/leetcode-master/0001.两数之和.md · GitHub
youngyangyang04/leetcode-master/0005.最长回文子串.md · GitHub
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 | LeetcodeGithub | 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 💃💃💃💃 | LeetcodeGithub | |
| Medium | 🟠❓ | 19. Remove Nth Node From End of List | LeetcodeGithub | |
| Difficulty | Marks | Name | link | Notes |
|---|
| Hard | 🟢✅ | 23. Merge k Sorted Lists | Leetcodelabuladong | Need to read the sample code |
| Easy | ❗ | 160. Intersection of Two Linked Lists | Leetcodelabuladong | Sample1 is interesting (recursion) |
labuladong
| 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 |
|---|
| 🟠 | | ❓ | | 370: Range Addition | Leetcode | Put off for now |
| 🟠 | | ✅🟢 | | 1094. Car Pooling | Leetcode | |
| 🟠 | | ❓ | | 1109. Corporate Flight Bookings | 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 |
|---|
| 🟠 | ✅ | 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)
- 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 |
|---|
| 🟠 | ✅ | 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 | |
Notes:
| 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
Notes:
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 |
| Difficulty | Marks | Name | link |
|---|
| 🟠 | ✅ | 2385. Amount of Time for Binary Tree to Be Infected | Leetcode |
| 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 |
|---|
| 🟠 | ✅❗❓❌ | 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 |
- 209: sliding window (left/right pointers)
- 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 vs l <= 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)