Skip to content

Latest commit

ย 

History

History
744 lines (521 loc) ยท 54.9 KB

README.md

File metadata and controls

744 lines (521 loc) ยท 54.9 KB

Code practice link


Difficulty Marks Name link Notes
๐ŸŸข โœ…โ—โ“โŒ Leetcode
๐ŸŸ  โœ…โ—โ“โŒ Leetcode
๐Ÿ”ด โœ…โ—โ“โŒ Leetcode

Markers:

  • โœ…/โœ”๏ธ 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

Difficulties:

  • ๐ŸŸข(Easy)
  • ๐ŸŸ (Medium)
  • ๐Ÿ”ด(Hard) ๐Ÿคจ

Kotlin

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

  1. 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
  1. Assertion (assertEqual)
test() assertEqual "expected" // for single answer
test().assertEqual("possible_output1", "possible_output2") // for multiple correct answers 
  1. Build-in data types
    1. Node (typealias IntNode = Node<Int>) and some built-in functions, e.g:
      1. fun <T> linkedNodesOf(vararg nodes: T) : Node<T> usage:linkedNodesOf(1, 2, 3) to create a linked nodes like 1 -> 2 -> 3
      2. fun <T> Node<T>.toList() : List<T> usage: linkedNodesOf(1, 2, 3).toList() gets: [1,2,3]
      3. fun <T, R> Node<T>.mapValue(transform: ((T)->R)) : List<R> usage: linkedNodesOf(1, 2, 3).mapValue{ it * 2 } gets [2,4,6]
      4. others see this file: Node

youngyangyang04/leetcode-master/0001.ไธคๆ•ฐไน‹ๅ’Œ.md ยท GitHub

Marks link Notes
๐ŸŸขโœ… 1. Two Sum
๐ŸŸขโœ… 342. Valid Anagram
๐ŸŸขโœ… 349. Intersection of Two Arrays
๐ŸŸข 383. Ransom Note
๐ŸŸขโœ… 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)

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
๐Ÿ”ด โŒ 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

Read List

TODO:

  • Quick sort
  • Quick select
  • depth first search

Binary search tree

  • 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

backtrack / dfs

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

References:


To-Do list