Apple | Consecutive integers in a unsorted array add to sum k

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-03-02Added By Anonymous
Source: Link

Given an array of integers of size N, find consecutive integers(sub array) which would sum up to S. If there are more than 1 sub-array which would sum up to S, list them all.


Sample input

[1,4,8,2,1,3,1]

S = 3


Expected Output

2,1

3

S = 4


Expected Output

4

1,3

3,1


expected O(n) solution

Comments