Posts

Leetcode June 11, 2025 -- Problem #3445

 Today's problem is #3445: Maximum Difference Between Even and Odd Frequency II. https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-ii/description/ This builds off of yesterday's problem. Notice, first of all, that the substring *subs* can be any size from k to len(s). At first glance, you might think this means that the largest difference will always come from the largest valid substring where there exists both an even and odd frequency -- I thought the same thing. However, with a little more thought, we can see that that might not always be true. Take for example, the case s = "1121122" .  The frequency of 1 is 4, and the frequency of 2 is 3, so the maximum difference is 1. However, look at the substring s[0:5] , which is "11211". Here, the frequency of 1 is 4, and the frequency of 2 is 1, so the maximum difference is 3. The obvious approach is to just run every substring through yesterday's maxDifference function, and then...

Leetcode June 10, 2025 -- Problem #3442

 Welcome to my coding blog! I'll mostly be posting about my experiences with Leetcode's daily problems for now, but if any other interesting coding projects come up then I'll definitely post about them here. I'm posting a day behind on the Leetcode problems, so today's problem is #3442, "Maximum Difference Between Even and Odd Frequency I". Take a look at the problem, and then we'll get started: https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/description/ Right away, I can see that this is going to revolve around looping procedures and string indexing. Seems like a job for Python. My first thought was to create a list of all 26 English characters and iterate through them one by one. However, it occured to me that, by just keeping track of whether a given character has already been analyzed, we can actually use the string itself as a map of all possible characters! As a bonus, this extends it from working with english l...