Max Erasure Value with Sliding Window and HashMap

📘 DSA Journey — Day 18 Today’s focus: Sliding Window with uniqueness constraint. Problem solved: • Maximum Erasure Value (LeetCode 1695) Concepts used: • Sliding Window / Two-pointer technique • HashMap for tracking elements • Maintaining running sum Key takeaway: The goal is to find the maximum sum of a subarray with all unique elements. Using a sliding window, we expand the window while elements are unique. If a duplicate is encountered, we shrink the window from the left until the duplicate is removed. A HashMap helps track the presence (or last occurrence) of elements efficiently. At the same time, we maintain a running sum of the current window. Whenever the window is valid (all unique), we update the maximum sum. This approach avoids recalculating subarrays and reduces the complexity to O(n). This problem highlights how combining sliding window + HashMap + running sum can efficiently handle uniqueness constraints. Continuing to strengthen pattern recognition and consistency in solving DSA problems. #DSA #Java #LeetCode #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories