Subarray with given sum
Lesson 24 of 26 in Coddy's Arrays in C++ course.
This is the most commonly asked question, in which we have to find is there any subarray that exists with the given sum.
Challenge
Complete the function GivenSum by returning true if there exists at least one subarray with a given sum else return false.
Try it yourself
#include<iostream>
using namespace std;
#include<vector>
bool GivenSum(vector<int>arr, int n, int sum){
//code here
}All lessons in Arrays in C++
2Memory Analysis
Memory Allocation8Subarray
IntroductionSubsequencePrinting all SubarraysSubarray with given sumCumulative sum of SubarrayKadane's Algorithm