How do you find a subarray with the given sum?
If it's not a big array you could use brute force: 2^n solutions!
I am given an array of elements and the sum K, and I am supposed to find a subarray (doesn’t have to be contiguous) whose sum is equal to K.
For example:
Input: [1, 9, 3, 2, 21], 30
Output: [9, 21]
Do I need to use backtracking or is there another algorithm using dynamic programming for example?