Posts

Showing posts from September, 2025

1600 LCs

Image
Happy to complete my 1600th LeetCode problem. I picked a Medium one to mark this milestone: remove from a linked list elements in a given array. Use a hash set to store the elements of the array for quick look-up. Deal with the head of the list separately, then the body. Code is down below, cheers, ACC. Delete Nodes From Linked List Present in Array - LeetCode ou are given an array of integers  nums  and the  head  of a linked list. Return the  head  of the modified linked list after  removing  all nodes from the linked list that have a value that exists in  nums .   Example 1: Input:   nums = [1,2,3], head = [1,2,3,4,5] Output:   [4,5] Explanation: Remove the nodes with values 1, 2, and 3. Example 2: Input:   nums = [1], head = [1,2,1,2,1,2] Output:   [2,2,2] Explanation: Remove the nodes with value 1. Example 3: Input:   nums = [5], head = [1,2,3,4] Output:   [1,2,3,4] Explanation: No node has value 5. ...

The power of pruning in backtracking V

Image
Backtracking is a great technique in algorithms, but it needs to be accompanied by aggressive pruning or else it may quickly become intractable. This was an interesting problem, and the small input numbers (10^5 and k<=5) tells me that the authors knew that this could quickly become intractable, even with pruning. The pruning here primarily happens in two occasions: first during the base case (k==0), second when the product becomes larger than n. Comparing my solution with Sonnet 4's and ChatGPT 5's (and I gave them all the hints too), there is a small gain in my solution compared to theirs. It was surprising to see that Anthropic's one didn't make use of pruning as well as mine's or ChatGPT 5's. Code is down below, cheers, ACC. Balanced K-Factor Decomposition - LeetCode Given two integers  n  and  k , split the number  n  into exactly  k  positive integers such that the  product  of these integers is equal to  n . Return  any ...