Posts

Showing posts from 2025

Classic Dynamic Programming IX

Image
A bit of vibe code together with OpenAI O3. I asked O3 to just generate the sieve due to laziness. Sieve is used to calculate the first M primes (when I was using Miller-Rabin, was giving me TLE). The DP follows from that in a straightforward way: calculate the numbers from i..n-1, then n follows by calculating the min over all M primes. Notice that I made use of Goldbach's Conjecture as a way to optimize the code too. Goldbach's Conjecture estates that any even number greater than 2 is the sum of 2 primes. The conjecture is applied in the highlighted line. Cheers, ACC. PS: the prompt for the sieve was the following, again using Open AI O3 Advanced Reasoning: " give me a sieve to find the first M prime numbers in C#. The code should produce a List<int> with the first M primes " Minimum Number of Primes to Sum to Target - LeetCode You are given two integers  n  and  m . You have to select a multiset of  prime numbers  from the  first   m  pri...

HashSet I

Image
HashSet is faster and more memory efficient than HashTable. If you don't need the actual hash value, only the hash set, prefer to use HashSet over HashTable. The solution to the problem below exemplifies this situation. I didn't test with HashTable, but I'm sure it would be slower. Cheers, ACC. Partition String - LeetCode Given a string  s , partition it into  unique segments  according to the following procedure: Start building a segment beginning at index 0. Continue extending the current segment character by character until the current segment has not been seen before. Once the segment is unique, add it to your list of segments, mark it as seen, and begin a new segment from the next index. Repeat until you reach the end of  s . Return an array of strings  segments , where  segments[i]  is the  i th  segment created.   Example 1: Input:   s = "abbccccd" Output:   ["a","b","bc","c","cc","d"] Explanation:...