MaximumLengthSubarray with target sum k not passing all test cases #F.A.A.N.G course

void findLenOfLargestSubarrWithSmZero(vector arr,int n,int k)

{

   unordered_map<int,int> mp;
   int len=0,pre=0;
  for(int i=0;i<n;i++)
  { 
    pre+=arr[i];  
  
    if(pre==k)
    { 
     len=max(len,i+1);    
    }
    
    if (mp.find(pre) == mp.end()) 
        mp[pre] = i; 

    if(mp.find(pre-k)!=mp.end())
    {
        len=max(len,i-mp[pre-k]);
    }
         

}
cout<<len;

}

I would like to add that I am not able to login to cb IDE and hence not able to share links for code

why?

u can simply share without login-in

i cant debug without the cb ide link
diff to debug ill formatted code

@SurbhiKohli
ok atleast share the entire code
where u take input in the desired manner
use ``` before and after the code ( tick signs)
it will come in formatted manner

 #include <bits/stdc++.h>
using namespace std;
void findLengthOfLargestSubarrayWithSumZero(vector<int> arr,int n,int k)
{
    unordered_map<int,int> mp;
    int len=0,pre=0;
    for(int i=0;i<n;i++)
    { 
      pre+=arr[i];  
      
        if(pre==k)
        { 
         len=max(len,i+1);    
        }
        
        if (mp.find(pre) == mp.end()) 
            mp[pre] = i; 
  
        if(mp.find(pre-k)!=mp.end())
        {
            len=max(len,i-mp[pre-k]);
        }
             
  
    }
    cout<<len;
}
int main(){
    int k;
   // cin>>n;
   string s;
   vector<int> vc;
cin>>s;
int len=s.length();
string ss;
for(int i=1;i<len;i++)
{  
    if(s[i]!=',' && s[i]!=']')
    {
        ss=ss+s[i];
    }
    else{
       // cout<<"encountered ,  .so string till now is "<<ss<<"and its int is "<<stoi(ss)<<endl;
        vc.push_back(stoi(ss));
        ss="";
    }
}


  int n=vc.size();

    cin>>k;
  findLengthOfLargestSubarrayWithSumZero(vc,n,k);
return 0;
}
```

@SurbhiKohli

bro!
this question is likee so mammoth

first of all the input
start by taking input using getline and not cin
cin will break as soon as space is encountered
so use cin

then process the input
check code for that
in that as well -ve and +ve no have to be dealt
add them to vec
then
the algo for the code

code