LC 1653 - Minimum Deletions to Make String Balanced

In this problme we need to removal character from string aab...bab containing only a and b, and make sure in the end it becomes aa..aab...b, find the minimum removal. I tried to count the prefix for how many b presents, and postifx for how many a presents, then when we want to seperate the string into two clusters, [.. idx] and [idx+1 ..], and make the first clsuter all a, and the second all b, we only need to add up prefBandpostA`. we check and maintan the best answer. ...

February 7, 2026 · 1 min

LC 1292 - Maximum Side Length of a Square with Sum Less than or Equal to Threshold

Approach I think that we can do a O(N^3) approach by maintaining prefix sum, and then do post processing to get the currnet sume for all pairs of square from i,j to i+k,i+k. My first version was slow where I use k=1 to end, it can be much faster by changing it to k=maxWith+1 to end; however, the worst case comeplxity is still large. An interseting part is the 2D prefix, it can be done easily by adding in the horizontal direction then the vertical direction. ...

January 19, 2026 · 3 min