GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — DSA/Array/SubarrayWithGivenSum.cpp at master · YOG3SHWAR/DSA Expand file tree/ Copy pathSubarrayWithGivenSum.cppMore file actions 16 lines (15 loc) · 455 Bytes / Copy pathSubarrayWithGivenSum.cppFile metadata and controls16 lines (15 loc) · 455 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // https://practice.geeksforgeeks.org/problems/subarray-with-given-sum-1587115621/1 public: vector<int> subarraySum(int arr[], int n, long long s) { long long sum = 0; int i = 0; for (int j = 0; j < n; j++) { sum += arr[j]; if (sum > s) while (sum > s) sum -= arr[i++]; if(sum == s) return {i+1, j+1}; } return {-1}; } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |