leetcodedaybyday - Beats 100% with C++ and Beats 100% with Python3
IntuitionThe problem requires checking if there exist at least two overlapping subarrays of size 2 with the same sum. By iterating through the array and using a
# Intuition
The problem requires checking if there exist at least two overlapping subarrays of size 2 with the same sum. By iterating through the array and using a hash set to store sums of subarrays, we can efficiently check for duplicates.

# Approach
1. **Iterate Over the Array**:
   - Traverse the array to calculate the sum of consecutive pairs of elements.
   
2. **Use a Hash Set for Storage**:
   - Store the sums of each subarray of size 2 in a hash set.
   - Before adding a sum, check if it already exists in the set.

3. **Return Early if Duplicate Found**:
   - If a duplicate sum is found during the iteration, return `True` immediately.

4. **Return Result**:
   - If no duplicate is found, return `False` after completing the iteration.

# Complexity
- **Time Complexity**:  
  \(O(n)\), where \(n\) is the length of the array. The iteration over the array takes \(O(n)\), and set operations (insert and lookup) are \(O(1)\) on average.

- **Space Complexity**:  
  \(O(n)\), for the hash set storing up to \(n-1\) sums.


# Code
```cpp []
class Solution {
public:
    bool findSubarrays(vector<int>& nums) {
        int n = nums.size();
        int count = 0;
        for (int i = 0; i < n - 1; i++){
            for (int j = i + 1; j < n - 1; j++){
                if (nums[j] + nums[j + 1] == nums[i] + nums[i + 1])
                    count++;
            }
        }
        return count >= 1;
    }
};



```
```python []
class Solution:
    def findSubarrays(self, nums: List[int]) -> bool:
        n = len(nums)
        hash_set = set()
        for i in range(n - 1):
            total = nums[i] + nums[i + 1]
            if total in hash_set:
                return True
            hash_set.add(total)
        return False
            



```


['C++', 'Python3']