➤ Problem Link : 1006C. Three Parts of the Array
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int n;
cin>>n;
ll arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
map<ll,ll> mp;
ll val=0;
for(int i=n-1;i>=0;i--)
{
val+=arr[i];
if(mp.find(val)==mp.end())
mp[val]=i;
}
val=0;
ll ans=0;
for(int i=0;i<n;i++)
{
val+=arr[i];
if(mp.find(val)!=mp.end() && mp[val]>i)
ans=max(ans,val);
}
cout<<ans;
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
