Blind 75 — Day 5 (Maximum Subarray)

Tiger Hong
2 min readJul 13, 2023

--

Ever get frustrated when your code times out even though your test cases pass? Well, I definitely understand how that feels! In today’s video, I find myself figuring out a basic solution though with terrible time complexity as I must admit. It’s important to understand that there are multiple different approaches to a solution!

Today I was unable to resolve that, but it gave me insight into thinking about problem-solving patterns and how I might be able better improve my skills! From today on, I will also include my learning process of what I learned from the problem through review and the correct solution.

My inital though process was to run a for-loop twice to examine first the value of the integer in the initial loop, and to then run a second loop to examine all the values after that integer. This would allow us to only examine the values after the initial loop integer and add those values to a “current value” variable. I would then compare that value to a variable named greatestSum and would override it if the sum of a group of integers that I found was greater. The video explains this process in a more digestible manner so please watch to find out more!

The roadblock we ran into today was again time complexity. It does not seem that running a double for-loop is time efficient and there are better methods for us to identify groupings of array values. I’ve learned that running two loops definitely is not O(n) and is O(n²) which makes me realize to learn more about time complexity!

Please see the solution below to see how we might be able to do so!

Solution: https://leetcode.com/problems/maximum-subarray/solutions/2704505/c-java-python3-javascript-faster-than-95-o-n/

Explanation of Solution: https://zyrastory.com/en/coding-en/leetcode-en/leetcode-53-maximum-subarray-solution-and-explanation-en/

--

--

Tiger Hong

Hi I'm Tiger! I'm a software engineer who's passionate about making an impact in the world. Follow my journey through Medium to see what I'm working on!