Target Sum
Learn Target Sum (Dynamic Programming, Advanced DSA) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Assigning + or - to Each Number to Hit a Target Given numbers and a target, assign a + or - sign to EACH number so the total equals target; count how many ways this is possible. The algebraic trick: split numbers into a POSITIVE group P and NEGATIVE group N. Since sum(P) - sum(N) = target and sum(P) + sum(N) = total , solving gives sum(P) = (total + target) / 2 - turning this into counting Subset Sum ways for that specific value.
More lessons in Dynamic Programming
- Fibonacci (DP)
- Climbing Stairs
- House Robber
- Kadane (DP)
- Grid Paths
- Unique Paths
- Minimum Path Sum
- 0/1 Knapsack
- Unbounded Knapsack
- Bounded Knapsack
- Subset Sum
- Equal Partition
- Longest Common Subsequence - LCS
- Longest Common Substring
- Edit Distance
- Longest Palindromic Subsequence
- Palindrome Partitioning
- Longest Increasing Subsequence - LIS
- Number of LIS
- Maximum Sum Increasing Subsequence
- Matrix Chain Multiplication
- Burst Balloons
- Optimal BST
- Diameter (Tree DP)
- Maximum Path Sum (Tree DP)
- Tree Independent Set
- Traveling Salesman Problem
- Assignment Problems
- Counting Numbers (Digit DP)
- Digit Constraints