question–>
https://practice.geeksforgeeks.org/problems/longest-sub-array-with-sum-k/0#
code–>
not passing all testcases!!
Longest Sub-Array with Sum K
Hey @sheikhhaji18
We always save 1st index of number to maximze array length
for(int i=0;i<n;i++){
pre+=arr[i];
if(pre==k){
maxi=max(maxi,i+1);
}
if(m.count(pre-k)){
maxi=max(maxi,i-m[pre-k]);
}
if(m.count(pre)==0)
{
m[pre]=i;
}
}