<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Prefix on Yu-Cheng's Notes</title><link>https://linkingmon.github.io/blog/tags/prefix/</link><description>Recent content in Prefix on Yu-Cheng's Notes</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Sat, 07 Feb 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://linkingmon.github.io/blog/tags/prefix/index.xml" rel="self" type="application/rss+xml"/><item><title>LC 1653 - Minimum Deletions to Make String Balanced</title><link>https://linkingmon.github.io/blog/coding/lc-1653/</link><pubDate>Sat, 07 Feb 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-1653/</guid><description>&lt;p&gt;In this problme we need to removal character from string &lt;code&gt;aab...bab&lt;/code&gt; containing only &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, and make sure in the end it becomes &lt;code&gt;aa..aab...b&lt;/code&gt;, find the minimum removal.&lt;/p&gt;
&lt;p&gt;I tried to count the prefix for how many &lt;code&gt;b&lt;/code&gt; presents, and postifx for how many &lt;code&gt;a&lt;/code&gt; presents, then when we want to seperate the string into two clusters, &lt;code&gt;[.. idx]&lt;/code&gt; and &lt;code&gt;[idx+1 ..], and make the first clsuter all &lt;/code&gt;a&lt;code&gt;, and the second all &lt;/code&gt;b&lt;code&gt;, we only need to add up &lt;/code&gt;prefB&lt;code&gt;and&lt;/code&gt;postA`. we check and maintan the best answer.&lt;/p&gt;</description></item><item><title>LC 1292 - Maximum Side Length of a Square with Sum Less than or Equal to Threshold</title><link>https://linkingmon.github.io/blog/coding/lc-1292/</link><pubDate>Mon, 19 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-1292/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;I think that we can do a &lt;code&gt;O(N^3)&lt;/code&gt; approach by maintaining prefix sum, and then do post processing to get the currnet sume for all pairs of square from &lt;code&gt;i,j&lt;/code&gt; to &lt;code&gt;i+k,i+k&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;My first version was slow where I use &lt;code&gt;k=1 to end&lt;/code&gt;, it can be much faster by changing it to &lt;code&gt;k=maxWith+1 to end&lt;/code&gt;; however, the worst case comeplxity is still large.&lt;/p&gt;
&lt;p&gt;An interseting part is the 2D prefix, it can be done easily by adding in the horizontal direction then the vertical direction.&lt;/p&gt;</description></item></channel></rss>