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 →

1190 LeetCode problem solution

LeetCode 1190. Reverse Substrings Between Each Pair of Parentheses can be solved in O(n) time using a stack, pair mapping, and direction reversal. First, we use a stack to match every pair of parentheses. Then traverse the string and, when a parenthesis is reached, jump to its pair and reverse the direction. This simulates reversing nested substrings without actually reversing them. Only letters are added to the result. This solution uses O(n) additional space.

3525 LeetCode problem solution

LeetCode 3525. Find X Value of Array II solution using Segment Tree, Prefix Product, and Modular Arithmetic patterns. Each segment tree node stores the segment product modulo k and counts of prefix products for every possible remainder. For each query, we perform a point update and query the range [start, n - 1], where cnt[x] gives the required x-value. The merge operation combines prefix-product counts while preserving their left-to-right order. Time complexity: O(n + q log n), Space complexity...