Valid Palindrome
Input: s = “A man, a plan, a canal: Panama”- ((charCode >= 48 && charCode <= 57) || (charCode >= 97 && charCode <= 122)) skip non alphanumeric char
– Start from both end until meet
– Compare each element from both end
– if no match exit
– else its palindrome
Is Subsequence
Input: s = “abc”, t = “ahbgdc” Output: true
Keep both index from string at 0
Iterate through target string
– if match char , increment both index
– else t index
– if s index at end subsequence found
Container With Most Water
Initialize two pointers
– Start from both ends of the array.
Initialize maxArea = 0
– Keeps track of the largest water container found so far.
Loop while left < right
– The container is formed by lines at left and right.
Compute area of current container
– area = (right – left) * Math.min(height[left], height[right])
– Width = distance between two pointers → (right – left)
– Height = shorter line → Math.min(height[left], height[right])
– Because water can’t go higher than the shorter side.
Update maximum area
– maxArea = Math.max(maxArea, area)
Move the pointer pointing to the smaller height
The smaller height limits the container’s height.
Moving it inward might find a taller line → potential larger area.
Moving the taller one doesn’t help since width also reduces.
Continue until pointers meet.
Return the maximum area found.
Three Sum
Sort the array → so duplicates are easier to handle.
Iterate over the array:
– Let current element = nums[i]
– Set two pointers:
– left = i + 1, right = n - 1
– While left < right:
– Compute sum = nums[i] + nums[left] + nums[right]
– If sum === 0: found a triplet → push it into result.
– Move left and right while skipping duplicates.
– If sum < 0: increase left
– If sum > 0: decrease right
Skip duplicate values for nums[i] too.


