Posts

Showing posts with the label SC01

Codechef::SC_01

  #include <bits/stdc++.h> using namespace std ; #define boost ios::sync_with_stdio( false ) ; cin.tie( 0 ) long long int subArrayExists ( long long int arr[] , long long int m) { unordered_set < int > sumSet ; // Traverse through array and store prefix sums long long int sum = 0 ; long long int count = 0 ; for ( long long int i = 0 ; i < m ; i++) { sum += arr[i] ; // If prefix sum is 0 or it is already present if (sum == 0 || sumSet.find(sum) != sumSet.end()) count ++ ; sumSet.insert(sum) ; } return count ; } int main (){ long long int n ; cin >> n ; long long int arr[n] ; for ( long long int i = 0 ; i < n ; ++i) { cin >> arr[i] ; } long long int m = sizeof (arr)/ sizeof (arr[ 0 ]) ; long long int count = subArrayExists(arr , m) ; cout << count << ' \n ' ; return 0 ; }