Menu
Coddy logo textTech

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 icon

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++