Internshala interview question

given an array and a number, find a cont sub-array whose sum equals to that given number.

Interview Answer

Anonymous

13 Aug 2020

Use sliding window and add elements from the starting index. If the sum of the subarray is greater than the required sum, start removing elements from the beginning of the subarray. In this way traverse the entire subarray until you find the answer.