Container With Most Water

Intuition Use two pointers, starting at the edges. Approach Use two pointer, starting at the edge. Always move the pointer with less height Complexity Time complexity: O(n) Space complexity: O(1) Code print(1)class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ start = 0 end = len(height)-1 maxVolume = -1 while start<end: h = min(height[start], height[end]) maxVolume = max(maxVolume, (end - start) * h) if height[start] < height[end]: start += 1 else: end -= 1 return maxVolume

April 24, 2025 · 1 min

Two Sum II - Input Array Is Sorted

Intuition Keep a map of the numbers, and lookup for it’s complement based on target. Approach Loop through all elements, check if the complement of the current number is already in the store. In case it’s true, return current index and the index stored. in case it’s not, add the current number to the store. The key here is to store the current number in the map, not the complement ...

April 22, 2025 · 1 min