Given an array of integers, find the maximum length of the sub-array having the given sum.

Let array `arr`

equal to `[ 5, 6, -5, 5, 3, 5, 3, -2, 0 ]`

and integer `sum`

equal to `8`

.

Sub-arrays with sum 8 are:

```
[ -5, 5, 3, 5 ]
[ 3, 5 ]
[ 5, 3 ]
```

The longest subarray is `[ -5, 5, 3, 5 ]`

, having the length 4. The solution should return the integer `4`

.

Contributed by Murat Sütunç

You are not signed in. You can only run/submit code after signing in. Create your free Codela account now!