Sharpen Your Algorithm Skills

This site is designed to help you explore different algorithmic approaches and problem-solving techniques, whether you're preparing for algorithm interviews or studying on your own to gain a deeper understanding of algorithms and data structures. Go step-by-step: read description > check solution > study examples > dig into the code.

Why do you need to solve LeetCode problems in the AI era?

This is a very easy and very hard question simultaneously. The short answer is - you do not need to do it. AI can do it very quickly and right for you. But the reality is much harder than we think.

Read more →

LeetCode 3900 problem - Prefix Sum pattern, O(n) complexity solution

LeetCode 3900. Longest Balanced Substring After One Swap combines the Prefix Sum pattern with a Hash Map technique to find the longest balanced substring after at most one swap. By tracking the difference between zeros and ones, we can determine whether a substring is already balanced or can be balanced with a single swap. The solution runs in O(n) time using a single pass through the string, with O(n) space for storing prefix balance information.

LeetCode 678 solution using the Greedy pattern

LeetCode 678. Valid Parenthesis String can be solved using the Greedy pattern by tracking a range of possible open parentheses. low represents the minimum possible number of unmatched '(', while high represents the maximum. For '*', the range expands because it can act as '(', ')', or an empty string. If high becomes negative, there are too many closing parentheses, so the string is invalid. At the end, the string is valid if low == 0. This approach runs in O(n) time and uses O(1) space complexi...