Question: Is there a way to solve this problem in time complexity O(log n), O(n), or O(n log n)? My solution has O(n^2), but I want

Is there a way to solve this problem in time complexity O(log n), O(n), or O(n log n)?

My solution has O(n^2), but I want to know the fastest solution.

Please let me know using Python.

> Given an array, find subarrays with a given sum.

example 1)

nums = [2, 7, 11, -2, 15], sum = 9, output = [[2, 7], [11, -2]]

example 2)

nums = [3, 5, 3, 7], sum = 8, output = [[3, 5]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!