1. You are given an array of N elements.
2. You are also given a number K.
3. You have to find the maximum length of a subarray whose sum is equal to K.
4. For example:
Input: arr = [3, 4, 2, 7, 1, 8] and K = 9
Output: 3
Explanation:
The subarrays with sum = 9 are:
[3, 4, 2] , [2, 7] and [1, 8]
The subarray with maximum length is [3, 4, 2] and its length is 3.
5. display is a utility function, feel free to use it for debugging purposes.
6. main takes input from the users and creates the array.
7. This is a functional problem.
8. You have to complete the maxLenSubarray function. It takes as input an array and K. It should return the maximum length of subarray whose sum is K. If no such subarray, it should return 0.
9. Don't change the code of main and display.
Input Format
First line takes input N, the length of the array. Second line takes input N space separated numbers representing the elements of the array. Third line takes input K. Input is handled for you.
Output Format
Maximum length of subarray whose sum is K if present, else 0. Output is handled for you.
Constraints
1 <= N <= 30000
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
6 3 4 2 7 1 8 9
Output
3