Posts

Showing posts from May, 2025

30.) DP on subsequences

Image
Subset sum = target✅⭐ Partition equal subset sum✅ Partition array into 2 subsets with min abs [sum(v1)-sum(v2) ]✅ Count subsets with sum k✅⭐ Count partitions with given diff✅ target sum✅ 0/1 knapsack✅⭐ min coins✅---->count min coins to be taken coin change-2--->count n(ways) of taking coins⭐✅ unbounded knapsack✅ rod cutting problem✅ ----------------------------------------------------------------------------------------------------------------------------- 2 ways to generate all subsequences- Power Set, or Recursion subset means subsequence in dsa ----------------------------------------------------------------------------------------------------------------------------- 1. Target Sum- QUES- return true if there exists a subset with sum equal to the target in the array... Soln assuming all array elements are positive  here f(n-1,target) will tell if there's a subsequence till n-1 index with sum = target 1.) RECURSIVE SOLN-        ( time: 2^n    ...

29.) 2D-dp, dp on grids, 3D-dp

Image
TOPICS- ninja's training✅ count all unique paths✅ count paths with obstacles✅ min path sum/                   fix st & fix end pts✅ min path sum in triangle/ fix st & var end pt✅ falling path sum /             var st & end pts✅ ninja & frnds/ 3d dp/       fix st & var end pts⭐✅ ----------------------------------------------------------------------------------------------------------- top down means top guy in recursion tree will get answer by going down bottom up means bottom guy will get answer by going up, or you start from the base case and accumulate all the stuff till top and get the answer ------------------------------------------------------------------------------------------------------------ recursive soln building- 1. write everything in index form 2. do all stuffs on that index 3. find way to get best/ optimal answer ------------------------ memoizati...