Skip to content

hereisderek/code_practice

Repository files navigation

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

About

coding practice, mostly on leetcode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages