Longest Sub-Array with Sum K
Problem Statement
Given an array containing N integers and an integer K., Your task is to find the length of the longest Sub-Array with the sum of the elements equal to the given value K.
Example 1:
Example 2:
Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function lenOfLongSubarr() that takes an array (A), sizeOfArray (n), sum (K)and returns the required length of the longest Sub-Array. The driver code takes care of the printing.
Expected Time Complexity: O(N). Expected Auxiliary Space: O(N).
Constraints: 1<=N<=105 -105<=A[i], K<=105
Intuition
Links
Video Links
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated