dsa2 min read
Longest Arithmetic Subsequence — DP + Hash Map per Index
Find the longest arithmetic subsequence using dp[i][diff] = length ending at index i with given difference.
Read →
1575 articles
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.
Design a URL shortener using two hash maps for O(1) encode and decode operations.