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

Ruby vs. Go

I’m curious about other type of language, and have a discussion with AI. I ask this question since when I tried to build my website with jeykll on my WSL system, it fails and had a lot of errors, and I tried to update some package but it is quite complicated, and then AI told me to use hugo and say that this is more stable. Hugo is more stable since this is build (and compiled) by go lang, and this is a compiled code, so its depedency is smaller and can be used in more system. Other compile code are C++, rusts. This type of language can be stable across OS/CI. ...

January 9, 2026 · 2 min

LC 865 - Smallest Subtree with all the Deepest Nodes

Approach My idea is to sweep the tree and collect the maxDeep and maxCnt, and then do the second pass to track the count for maxDeep, and return the first node that has cnt reaching maxCnt`. Code in code-1. After this I ask AI to have an optimized version, and it give me code-2, where we can directly store the depest node, and its ancestors. when left and right subtree have the same deep, we can return the current subtree and the deep+1, else we return the best solution among two subtree. ...

January 9, 2026 · 2 min

LC 295 - Find Median from Data Stream

Approach I waw originally thinking that we can insert the number with binary search (or lower_bound), and find median with directly taking the number from index for the vector. This strategy can pass the porlbme, but this is actually an O(N) solution since vector insert can be O(n). I then find out that we can maintain a minheap and maxheap with O(lgN) insertion time, and we only need to rebalance two heaps when their size is different by more than 2. ...

January 9, 2026 · 2 min

LC 23 - Merge k Sorted Lists

Approach This is actually quite simple, just take the smallest from all list and connect, and iteratively do this process, and will use a min heap instead for faster min-val query. I also tried a new method for defining the comparator for priority_queue this time. Usually I will use a comparator class and a bool operator(), but I found that there is a more clear way to write this, that is to define the lambda function first, and pass the function to pq’s constructor. ...

January 9, 2026 · 1 min

LC 224 - Basic Calculator

Approach This problem is not hard but need to consider some special conditions. I found that actually we just need to trace the actual sign after removing the parantheses. For instance, 1-(2-(3+4)) is equal to 1-2+3+4, so we need to buffer the current actual sign when we get the (. In this case, we stack - when getting the first (, and when approaching the second (, we know that it is negative outside, and this is negative so we need to invert the sign inside this parantheses, so stack + inside. And the sign is removed after ) is encountered. ...

January 9, 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

LC 42 - Trapping Rain Water

Approach I was orginally thinking that we can colelct all the peaks, and fill the water between peaks, but finding that this might not be correct. For example like [2,0,1,0,1,0,2], if we fill between peaks, the 3-rd (0-indexed) would be 1, but it is actaully 2. Later I come up with the idea for using mono stack. We collect all the points in increasing order, and try to fill from one to another. We also do the same thing backwards, since the mono-stack would stop on the largest element. ...

January 8, 2026 · 2 min

LC 1458 - Max Dot Product of Two Subsequences

Approach Today’s daily is quite strait forward, the optimal structure is presented so we can leverage DP. For maxProd([idx1 ..], [idx2 ..]), we can split into subproblems: Take idx1 & idx2 for SP, and don’t do SP for the rest -> nums[idx1] * nums[idx2] Take idx1 & idx2 for SP, and try to add with next solution -> nums[idx1] * nums[idx2] + maxProd([idx1+1 ..], [idx2+1 ..]) Let idx1 pair with others -> maxProd([idx1 ..], [idx2+1 ..]) Let idx2 pair with others -> maxProd([idx1+1 ..], [idx2 ..]) Notice that for situation 2, 3, 4, the need to make sure that at least one element is paired (we cannot have empty pairs) Code class Solution { public: int maxDotProduct(vector<int>& nums1, vector<int>& nums2) { int m = nums1.size(); int n = nums2.size(); memo.assign(m, vector<int>(n, -1)); return traverse(nums1, nums2, 0, 0); } int traverse(const vector<int>& nums1, const vector<int>& nums2, int idx1, int idx2) { if(idx1 == nums1.size() || idx2 == nums2.size()) return INT_MIN; if(memo[idx1][idx2] != -1) return memo[idx1][idx2]; int maxSP = INT_MIN; maxSP = max(nums1[idx1]*nums2[idx2], maxSP); int nextSP = traverse(nums1, nums2, idx1+1, idx2+1); if(nextSP != INT_MIN) maxSP = max(nums1[idx1]*nums2[idx2] + nextSP, maxSP); nextSP = traverse(nums1, nums2, idx1, idx2+1); if(nextSP != INT_MIN) maxSP = max(maxSP, nextSP); nextSP = traverse(nums1, nums2, idx1+1, idx2); if(nextSP != INT_MIN) maxSP = max(maxSP, nextSP); memo[idx1][idx2] = maxSP; return maxSP; } vector<vector<int>> memo; };

January 8, 2026 · 2 min

LC 1339 - Maximum Product of Splitted Binary Tree

Approach I find that any node (except the root), can be split into a differnt subtree, and the remaining nodes are in another subtree. Therefore, all we have to do is to calculate the sum of the subtree, and the overall sum for all nodes, and try to calculate the maximum product. Code class Solution { public: const int mod = 1'000'000'007; int maxProduct(TreeNode* root) { vector<long long> nodeSum; long long sum = traverse(root, nodeSum); nodeSum.pop_back(); long long maxP = LONG_MIN; for(const auto& s: nodeSum) { long long curP = (sum - s) * s; maxP = max(maxP, curP); } return maxP % mod; } long long traverse(TreeNode* root, vector<long long>& nodeSum) { long long sum = 0; if(root->left) sum += traverse(root->left, nodeSum); if(root->right) sum += traverse(root->right, nodeSum); sum += root->val; nodeSum.push_back(sum); return sum; } };

January 7, 2026 · 1 min