Untitled
user_5763442009
plain_text
2 years ago
550 B
0
Indexable
Never
vector<int> subarraySum(int arr[], int n, long long s) { unsigned long long sum=0; int j=0; for(int i=0;i<n;i++){ while(sum>s){ sum-=arr[j]; j++; } if (sum==s){ return {j+1,i}; } if(i<n) sum+=arr[i]; } } //https://practice.geeksforgeeks.org/problems/subarray-with-given-sum-1587115621/1?page=1&company[]=Amazon&com//pany[]=Microsoft&company[]=Google&category[]=Arrays&sortBy=submissions