Longest Subarray Sum B

Given an array of integers A of size N and an integer B.
Find the length of longest subarray having sum equal to B.

If no such subarray exists then return -1.



Input Format

The First argument given is the integer array A.
The Second argument is an integer B.

Output Format

Return the length of longest subarray having sum equal to B if exists else return -1.

Constraints

1 <= N <= 100000
-10^6 <= A[i] <= 10^6
-10^9 <= B <= 10^9

For Example

Input 1:
    A = [1, 2, 3, 4, 5]
    B = 10
    
Output 1:
    4

Input 2:
    A = [1, -1, -1, 1]
    B = 0
Output 2:
    4
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Longest Subarray Sum B on Interview Code Editor
Sign Up
to access hints and editorial solutions for Longest Subarray Sum B

Discussion


Loading...
Click here to start solving coding interview questions