Skip to content

Repository files navigation

Code practice link


DifficultyMarksNamelinkNotes
🟢✅❗❓❌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)
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
  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

MarkslinkNotes
🟢✅1. Two Sum
🟢✅342. Valid Anagram
🟢✅349. Intersection of Two Arrays
🟢383. Ransom Note
🟢✅49. Group Anagrams

youngyangyang04/leetcode-master/0005.最长回文子串.md · GitHub

MarkslinkNotes
🟠✅647. Palindromic Substrings
🟠❗❓5. Longest Palindromic Substring

youngyangyang04/leetcode-master/0005.最长回文子串.md · GitHub

DifficultyMarkslinkNotes
Medium✅❗5. Longest Palindromic Substring [leetcode] [git]
Medium15. 3Sum 💃💃💃 [leetcode] [git]My4 not done

DifficultyMarksNamelinkNotes
Easy🟠✅
Medium🟢✅17. Letter Combinations of a Phone NumberLeetcodeGithubDidn't read the sample code since it didn't take me too much thinking to solve the question, but it might worth a read
MediumSkipped for now18. 4Sum 💃💃💃💃LeetcodeGithub
Medium🟠❓19. Remove Nth Node From End of ListLeetcodeGithub

DifficultyMarksNamelinkNotes
Easy🟢✅21. Merge Two Sorted ListsLeetcodelabuladongSample1 is interesting (recursion)
Easy🟢✅141. Linked List CycleLeetcode
Medium142. Linked List Cycle IILeetcodelabuladong

DifficultyMarksNamelinkNotes
Hard🟢✅23. Merge k Sorted ListsLeetcodelabuladongNeed to read the sample code
Easy160. Intersection of Two Linked ListsLeetcodelabuladongSample1 is interesting (recursion)

labuladong

DifficultyMarksNamelinkNotes
Easy🟢876. Middle of the Linked ListLeetcodeFaster than 100% submission 🟢🟢
Medium92. Reverse Linked List IILeetcodeMy2
Easy🟠✅206. Reverse Linked ListLeetcodeNeed to check sample and read this and read S1

DifficultyMarksNamelinkNotes
Hard🔴❗❗❓25. Reverse Nodes in k-GroupLeetcode

TODO:


DifficultyMarksNamelinkNotes
🟢234. Palindrome Linked ListLeetcode
🟢26. Remove Duplicates from Sorted ArrayLeetcode
🟢27. Remove ElementLeetcode
🟢83. Remove Duplicates from Sorted ListLeetcode

TODO: Leetcode_710


DifficultyMarksNamelinkNotes
🟠✅🟢167. Two Sum II - Input Array Is SortedLeetcode
🟢283. Move ZeroesLeetcode

DifficultyMarksNamelinkNotes
🟢344. Reverse StringLeetcode
🟢303. Range Sum Query - ImmutableLeetcode
🟠304. Range Sum Query 2D - ImmutableLeetcode

Leetcode 370: Range Addition


DifficultyMarksNamelinkNotes
🟠370: Range AdditionLeetcodePut off for now
🟠✅🟢1094. Car PoolingLeetcode
🟠1109. Corporate Flight BookingsLeetcode
🟠48. Rotate ImageLeetcode

DifficultyMarksNamelinkNotes
🟠54. Spiral MatrixLeetcode

DifficultyMarksNamelinkNotes
🟠59. Spiral Matrix IILeetcode
🟠✅❓3. Longest Substring Without Repeating CharactersLeetcodeTODO: read explanation

DifficultyMarksNamelinkNotes
🔴76. Minimum Window SubstringLeetcode
🟠34. Find First and Last Position of Element in Sorted ArrayLeetcode
🟠1109. Corporate Flight BookingsLeetcode

DifficultyMarksNamelinkNotes
🟠11. Container With Most WaterLeetcode
🔴✅❗❓❌42. Trapping Rain WaterLeetcode

DifficultyMarksNamelinkNotes
🟠238. Product of Array Except SelfLeetcode
🟢217. Contains DuplicateLeetcode
🟠347. Top K Frequent ElementsLeetcode1. Heatmap, 2. bucket list/sort
🟢125. Valid PalindromeLeetcode
🟠271. Encode and Decode StringsLintcode_659

DifficultyMarksNamelinkNotes
🟠128. Longest Consecutive SequenceLeetcode
🟢121. Best Time to Buy and Sell StockLeetcode
🟠✅❓424. Longest Repeating Character ReplacementLeetcode
🟠567. Permutation in StringLeetcode

DifficultyMarksNamelinkNotes
🔴✅❗❓❌239. Sliding Window MaximumLeetcode
🟢20. Valid ParenthesesLeetcode
🟠✅❗155. Min StackLeetcodeThe use of miniStack in S1 and S2

DifficultyMarksNamelinkNotes
🟠150. Evaluate Reverse Polish NotationLeetcode
🟠✅❓22. Generate ParenthesesLeetcode
🟢✅❗❓❌496. Next Greater Element ILeetcode

DifficultyMarksNamelinkNotes
🟠739. Daily TemperaturesLeetcode
🟠853. Car FleetLeetcode
 | |

DifficultyMarksNamelinkNotes
🔴84. Largest Rectangle in HistogramLeetcode
🟢704. Binary SearchLeetcode
🟠74. Search a 2D MatrixLeetcode
🟠✅❗875. Koko Eating BananasLeetcode
🟠33. Search in Rotated Sorted ArrayLeetcode
🟢✅❗❓❌Leetcode
🟠✅❗❓❌Leetcode
🔴✅❗❓❌Leetcode

DifficultyMarksNamelinkNotes
🟠✅❗❓❌143. Reorder ListLeetcode
🟢✅❗❓❌Leetcode
🟠✅❗❓❌Leetcode
🔴✅❗❓❌Leetcode

DifficultyMarksNamelinkNotes
🟠138. Copy List with Random PointerLeetcode

DifficultyMarksNamelinkNotes
🟠2. Add Two NumbersLeetcode
🟠287. Find the Duplicate NumberLeetcode
🟠146. LRU CacheLeetcode

DifficultyMarksNamelinkNotes
🟢226. Invert Binary TreeLeetcode
🟢✅❗104. Maximum Depth of Binary TreeLeetcode
🟢110. Balanced Binary TreeLeetcode
🟢100. Same TreeLeetcode
🟢✅❗572. Subtree of Another TreeLeetcode
  • 572: can use a utility method isSameTree to check or need to be careful (see solution)

DifficultyMarksNamelinkNotes
🟢235. Lowest Common Ancestor of a Binary Search TreeLeetcode
🟢✅❗❓❌703. Kth Largest Element in a StreamLeetcode
🟢1046. Last Stone WeightLeetcode
🟢70. Climbing StairsLeetcode
🟢746. Min Cost Climbing StairsLeetcode
🟢✅❗❓❌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.

DifficultyMarksNamelinkNotes
🟢136. Single NumberLeetcode
🟢✅❗191. Number of 1 BitsLeetcode
🟢338. Counting BitsLeetcode
🟢190. Reverse BitsLeetcode
🟢✅❗❓❌268. Missing NumberLeetcode
  • 191: use mod n = n % 2

DifficultyMarksNamelinkNotes
🟠208. Implement Trie (Prefix Tree)Leetcode
🟠211. Design Add and Search Words Data StructureLeetcode
🟠981. Time Based Key-Value StoreLeetcode
🟠973. K Closest Points to OriginLeetcode
🟠215. Kth Largest Element in an ArrayLeetcode
🟠78. SubsetsLeetcodetry to solve with single res: ArrayList
🟠✅❗❓❌39. Combination SumLeetcodeS1

DifficultyMarksNamelinkNotes
🟠46. PermutationsLeetcode
🟠✅❗❓❌90. Subsets IILeetcode

DifficultyMarksNamelinkNotes
🟠40. Combination Sum IILeetcode
🟠✅❗200. Number of IslandsLeetcode

DifficultyMarksNamelinkNotes
🟠✅❗❓❌695. Max Area of IslandLeetcode
🟠✅❗❓❌133. Clone GraphLeetcode

DifficultyMarksNamelinkNotes
🟠417. Pacific Atlantic Water FlowLeetcoderevert: ocean to land
🟠✅❗❓❌130. Surrounded RegionsLeetcode

Note:

  • 130: reverse thinking, thanks all non-surrounded region to T and change all O to X then change Ts back to O

DifficultyMarksNamelinkNotes
🟠✅❗198. House RobberLeetcode

DifficultyMarksNamelinkNotes
🟠✅❗❓❌322. Coin ChangeLeetcode
🟠✅❗❓❌91. Decode WaysLeetcode

DifficultyMarksNamelinkNotes
🟠36. Valid SudokuLeetcode
🟠✅❗❓❌53. Maximum SubarrayLeetcode

DifficultyMarksNamelinkNotes
🟠✅❗134. Gas StationLeetcode
🟠✅❓❓55. Jump GameLeetcode
🟠✅❓45. Jump Game IILeetcode

Notes:

  • 55: M4
  • 134: S1

DifficultyMarksNamelinkNotes
🟠846. Hand of StraightsLeetcode
🟠✅❓57. Insert IntervalLeetcode

DifficultyMarksNamelinkNotes
🟠✅❗❓❌102. Binary Tree Level Order TraversalLeetcode

DifficultyMarksNamelinkNotes
🟠199. Binary Tree Right Side ViewLeetcode
🟠1448. Count Good Nodes in Binary TreeLeetcode
🟠98. Validate Binary Search TreeLeetcode
🟠✅❗230. Kth Smallest Element in a BSTLeetcode
🟠✅❗❗❗105. Construct Binary Tree from Preorder and Inorder TraversalLeetcode
🟠✅❗❓❌211. Design Add and Search Words Data StructureLeetcode
🟠✅❓621. Task SchedulerLeetcode

Notes:

  • bfs - order level traversal
  • 98: binary search tree - sorted order
  • 230: solution

DifficultyMarksNamelinkNotes
🟢✅❗❓❌Leetcode
🟠✅❓355. Design TwitterLeetcode
🟠332. Reconstruct ItineraryLeetcode
🟠✅❓1584. Min Cost to Connect All PointsLeetcode

Notes:

  • 1584: Read S2 and link

DifficultyMarksNamelinkNotes
🟢✅❗❓❌Leetcode
🟠143. Reorder ListLeetcode
🟠146. LRU CacheLeetcode
🟠23. Merge k Sorted ListsLeetcode
🔴25. Reverse Nodes in k-GroupLeetcode
🟠211. Design Add and Search Words Data StructureLeetcode
🟠❗❓❌4. Median of Two Sorted ArraysLeetcode
🟠130. Surrounded RegionsLeetcode

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

DifficultyMarksNamelink
🟠✅❗❓❌743. Network Delay TimeLeetcode
🟠✅❗❓❌295. Find Median from Data StreamLeetcode

DifficultyMarksNamelink
🟠79. Word SearchLeetcode

DifficultyMarksNamelink
🟠131. Palindrome PartitioningLeetcode
🟠✅❗❓❌17. Letter Combinations of a Phone NumberLeetcode

DifficultyMarksNamelink
🟠663 · Walls and GatesLeetcode
🟠207. Course ScheduleLeetcode
  • 207: S1

DifficultyMarksNamelink
🟠✅❗❓❌684. Redundant Connection[Leetcode](// https://leetcode.com/problems/redundant-connection/)

DifficultyMarksNamelink
🟠2385. Amount of Time for Binary Tree to Be InfectedLeetcode
  • 2385: S1

DifficultyMarksNamelink
🔴✅❗❓❌4. Median of Two Sorted ArraysLeetcode

DifficultyMarksNamelink
🟠✅❗❓❌8. String to Integer (atoi)Leetcode
🟠✅❗❓❌56. Merge IntervalsLeetcode
  • 8: stupid ass question, not worth looking at

DifficultyMarksNamelink
🟠435. Non-overlapping IntervalsLeetcode
🟠✅❗❓❌Lintcode 919 · Meeting Rooms IILeetcodeyoutube

DifficultyMarksNamelink
🟠Leetcode
🟠73. Set Matrix ZeroesLeetcode
🟠50. Pow(x, n)Leetcode
🟠371. Sum of Two IntegersLeetcode
🟢202. Happy NumberLeetcode
🟢66. Plus OneLeetcode

DifficultyMarksNamelink
🟠338. Counting BitsLeetcode
🟠✅❗❓❌91. Decode WaysLeetcode

DifficultyMarksNamelink
🟠✅❗❓❌213. House Robber IILeetcode
  • 213: run house robber 1 two times with either first house included or the last

DifficultyMarksNamelink
🟠✅❗❓❌322. Coin ChangeLeetcode

DiffMarksNamelink
🟠✅❗743. Network Delay TimeLeetcode
🟠209. Minimum Size Subarray SumLeetcode
🟠✅❗❓❌Leetcode
🟠✅❗❓❌Leetcode
🟠✅❗❓❌Leetcode
🟢✅❗❓❌Leetcode
🟢✅❗❓❌977. Squares of a Sorted ArrayLeetcode
🔴✅❗❓❌Leetcode
  • 209: sliding window (left/right pointers)

DiffMarksNamelink
🟠✅❗❓❌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

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages