LeetCode 53. Maximum Subarray - divide and conquer approach
In the previous article, we explored how to optimize LeetCode 53: Maximum Subarray, starting with a Brute Force solution, moving to Dynamic Programming, and finally reducing space complexity to O(1) with Kadane's Algorithm. In this post, we'll take a different approach and solve the same problem using Divide and Conquer. We'll break the array into smaller parts, solve each part recursively, and see how combining the results helps us find the maximum subarray sum.
Read moreLeetCode 53. Maximum Subarray - from brute Force to Kadane's algorithm
In this post, I'll use LeetCode 53: Maximum Subarray to show how to move from a brute-force approach to Dynamic Programming, and then optimize the space complexity to O(1) and time complexity to O(n).
Read moreLeetCode 4006: imperative vs functional solution
This article covers LeetCode 4006: Count Valid Prefixes, with solutions in Python, Java, and Erlang using the Prefix Sum and Counting patterns. Each solution tracks the difference between zeros and ones to determine whether a prefix can be rearranged into an alternating binary string. I compare imperative loops in Python and Java with Erlang's functional approach using binary pattern matching and tail recursion.
Read moreLeetCode 1190: Stack vs. DP vs. Optimal Solution
LeetCode 1190: Reverse Substrings Between Each Pair of Parentheses using Stack, Dynamic Programming, and Paired Indices. Each solution includes code, simple explanations, examples, and time and space complexity. Let's compare the three approaches and see how to solve the problem in O(n) time.
Read more5 LeetCode Parentheses problems: patterns, approaches, and key lessons
In this post, I provide an in-depth analysis of five LeetCode parentheses problems, exploring Stack, Backtracking, Greedy, and Dynamic Programming, explaining why each approach works, when to use it, and how these algorithmic patterns differ.
Read more