Hi,
I can think of an approach that is neither recursion nor dynamic
programming. ( I would like to know, how to solve it using dp, as you say,
though)
1. Take an auxiliary array SUM which stores the sum of all entries from
beginning to that index.
2. Now, you have to find all the pairs(i,j | j >
Given an array of n elements(both +ve -ve allowed)
Find all the subarrays with a given sum k!
I know the solution using dynamic programming. It has to be done by
recursion (as asked by the interviewer)
For ex
arr = 1 3 1 7 -4 -11 3 4 8
k = 12
answer = {1 3 1 7}, {4 8}, {1 3 1 7 -4 -11 3 4 8}