LC - Floyds slow fast pointer

Detect Loop Recently I practice the topic for floyd’s fast slow pointer algorithm to detect loop. The basic problem is that there is a link list with cycle (that is each node only points to at most one node), we can detect it by walking a fast pointer (do two ->next per loop), and slow pointer (one ->next at a time). In this case, there is a loop if two pointers can meet each other. ...

January 13, 2026 · 3 min

LC 1235 - Maximum Profit in Job Scheduling

Approach this is a dp like problem, we maintain for each endTime what is the best profit, then for the next subproblem, we just combine the sub-solution for taking current interval or not. If we take hte current interval, we use the upper_bound to get the best cost that end before the starting time of current interval, otherwise we take the privious solution. One part that we need to be careful with is the duplicated endTime, we need to maintain the max if there are multiple intervals with the same endTime. ...

January 10, 2026 · 2 min

LC 127 - Word Ladder

Approach I was thinking a naive approach to build the graph for neighbor string first, and then try to do BFS. so the adjacency list part is TC O(MN^2), and the BFS part is O(M). I saw a different method and think that it has lower complexity (actually not). We put the beginning number into the queue for BFS, and its neighbor is having at most O(25M) neighbors, since we can change one character among M to any other 25 characters, and we only need to hash the wordList and find if it is in the hash. If it is present in the hash we erase it and put it into the queue. In this case, all the element ahve at most 25M neighbor, and number of traversal is at most N, but the complexity is still O(M^2N) since hashing a length M string is O(M). ...

January 9, 2026 · 3 min