dsa2 min read
Two Sum IV - BST — Hash Set + In-Order Traversal
Find if a BST contains two nodes summing to target using a hash set during DFS traversal.
Read →
webcoderspeed.com
1276 articles
Find if a BST contains two nodes summing to target using a hash set during DFS traversal.
Find the longest arithmetic subsequence using dp[i][diff] = length ending at index i with given difference.
Count pairs (i,j) where j-i != nums[j]-nums[i] by counting good pairs via frequency map of nums[i]-i.
Find the smallest subarray to remove so the remaining sum is divisible by p using prefix modular arithmetic.
Count tuples (a,b,c,d) where a*b=c*d by counting pairs with each product using a frequency map.