Posts

Showing posts from July, 2025

Sieve of Eratosthenes to solve a Leetcode problem III

Image
In this case the Sieve is applied directly to the main loop. Notice that you don't need to save off the elements in different arrays, only add them up. Also important to note that composite numbers can be created in multiple ways (for example, 2*6 == 3*4), hence keep track of which ones you have seen before to avoid double counting. No GAI involved, except at the very bottom to compute the Big-O time complexity, which I think it would have been of the order of NLogN, but the true analysis from OpenAI O3 (Advanced Reasoning) is down below. So is the code. Cheers, ACC. Split Array by Prime Indices - LeetCode You are given an integer array  nums . Split  nums  into two arrays  A  and  B  using the following rule: Elements at  prime  indices in  nums  must go into array  A . All other elements must go into array  B . Return the  absolute  difference between the sums of the two arrays:  |sum(A) - sum(B)| . Note: ...

Quasi FSM (Finite State Machine) problem + Vibe

Image
Not really an FSM problem since the state isn't changing, it is just defined by the current input. Simply following the instructions should do it. Using VSCode IDE you can also engage the help of Cline or Copilot for a combo of coding and vibe coding, see below screenshot. Cheers, ACC. Process String with Special Operations I - LeetCode You are given a string  s  consisting of lowercase English letters and the special characters:  * ,  # , and  % . Build a new string  result  by processing  s  according to the following rules from left to right: If the letter is a  lowercase  English letter append it to  result . A  '*'   removes  the last character from  result , if it exists. A  '#'   duplicates  the current  result  and  appends  it to itself. A  '%'   reverses  the current  result . Return the final string  result  after processing all char...